From d4c5a137a1650bb4dec3d03973526f3ab5ef8d3f Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Tue, 9 Aug 2022 13:50:27 +0300 Subject: [PATCH] Add examples for pushing artifacts with GH Actions Signed-off-by: Stefan Prodan --- action/README.md | 82 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/action/README.md b/action/README.md index 7a432d6b..f2871b76 100644 --- a/action/README.md +++ b/action/README.md @@ -32,7 +32,7 @@ You can download a specific version with: - name: Setup Flux CLI uses: fluxcd/flux2/action@main with: - version: 0.8.0 + version: 0.32.0 ``` ### Automate Flux updates @@ -74,6 +74,86 @@ jobs: ${{ steps.update.outputs.flux_version }} ``` +### Push Kubernetes manifests to container registries + +Example workflow for publishing Kubernetes manifests bundled as OCI artifacts to GitHub Container Registry: + +```yaml +name: push-artifact-staging + +on: + push: + branches: + - 'main' + +permissions: + packages: write # needed for ghcr.io access + +env: + OCI_REPO: "oci://ghcr.io/my-org/manifests/${{ github.event.repository.name }}" + +jobs: + kubernetes: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Flux CLI + uses: fluxcd/flux2/action@main + - name: Generate manifests + run: | + kustomize build ./manifests/staging > ./deploy/app.yaml + - name: Push manifests + run: | + flux push artifact $OCI_REPO:$(git rev-parse --short HEAD) \ + --path="./deploy" \ + --source="$(git config --get remote.origin.url)" \ + --revision="$(git branch --show-current)/$(git rev-parse HEAD)" + - name: Deploy manifests to staging + run: | + flux tag artifact $OCI_REPO:$(git rev-parse --short HEAD) --tag staging +``` + +Example workflow for publishing Kubernetes manifests bundled as OCI artifacts to Docker Hub: + +```yaml +name: push-artifact-production + +on: + push: + tags: + - '*' + +env: + OCI_REPO: "oci://docker.io/my-org/app-config" + +jobs: + kubernetes: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Flux CLI + uses: fluxcd/flux2/action@main + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Generate manifests + run: | + kustomize build ./manifests/production > ./deploy/app.yaml + - name: Push manifests + run: | + flux push artifact $OCI_REPO:$(git tag --points-at HEAD) \ + --path="./deploy" \ + --source="$(git config --get remote.origin.url)" \ + --revision="$(git tag --points-at HEAD)/$(git rev-parse HEAD)" + - name: Deploy manifests to production + run: | + flux tag artifact $OCI_REPO:$(git tag --points-at HEAD) --tag production +``` + ### End-to-end testing Example workflow for running Flux in Kubernetes Kind: