From d381bb37873f787edb285773ba852dad76d38a33 Mon Sep 17 00:00:00 2001 From: Marc Barry <4965634+marc-barry@users.noreply.github.com> Date: Thu, 9 Nov 2023 16:21:20 -0500 Subject: [PATCH] Support Docker image building and pushing via GitHub actions. --- .github/workflows/docker-image.yml | 56 ++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..fe62deb --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,56 @@ +name: Docker Image CI + +on: + push: + branches: ["main"] + tags: + - "v*" + pull_request: + branches: ["main"] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Get current branch or tag + id: get_ref + run: | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then + REF_NAME="${{ github.event.pull_request.head.ref }}" + else + REF_NAME=$(echo ${GITHUB_REF#refs/*/}) + fi + echo "REF_NAME=$REF_NAME" >> $GITHUB_ENV + echo "Current ref is: $REF_NAME" + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: us-docker.pkg.dev/qpoint-edge/public/kubernetes-qtap-operator + tags: | + type=sha + type=raw,value=branch-${{ env.REF_NAME }},enable=${{ env.REF_NAME != 'main' }} + type=raw,value=release-${{ env.REF_NAME }},enable=${{ startsWith(env.REF_NAME, 'v') }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GAR + uses: docker/login-action@v3 + with: + registry: us-docker.pkg.dev + username: _json_key + password: ${{ secrets.GAR_JSON_KEY }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64