From 4c8fe2b7fcbafd902b4cfc4651b0295c81eb4dd2 Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Wed, 19 Jun 2024 10:33:33 +0100 Subject: [PATCH] Unify production and test image builder jobs in one --- .github/workflows/build-an-image.yml | 87 ++++++++++++++++++++ .github/workflows/build-dev-image.yml | 79 ++---------------- .github/workflows/build-production-image.yml | 58 ++----------- 3 files changed, 100 insertions(+), 124 deletions(-) create mode 100644 .github/workflows/build-an-image.yml diff --git a/.github/workflows/build-an-image.yml b/.github/workflows/build-an-image.yml new file mode 100644 index 0000000..df0157d --- /dev/null +++ b/.github/workflows/build-an-image.yml @@ -0,0 +1,87 @@ +name: Build Developer Image + +on: + workflow_call: + inputs: + IMAGE_NAME: + required: true + type: string + BUILD_DIR: + required: true + type: string + TEST_TAG: + required: true + type: string + PUSH_TAG: + required: true + type: string + +env: + REGISTRY: ghcr.io + + +jobs: + build: + name: Build Image + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v3 + + # This only gets the date in this job, because + # there is no release tag + - name: Get release info + id: release_info + run: | + echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT + echo "" + + - name: Build docker image + uses: docker/build-push-action@v5 + with: + context: ${{ inputs.BUILD_DIR }} + file: ${{ inputs.BUILD_DIR }}/Dockerfile + # the load option means the built image is kept locally + # but not pushed yet + load: true + build-args: | + TX_DOCKER_VERSION=${{ github.sha }} + TX_RELEASE_TAG=dev-${{ steps.release_info.outputs.date }} + TX_RELEASE_DATE=${{ steps.release_info.outputs.date }} + tags: ${{ inputs.TEST_TAG }} + cache-from: type=gha + cache-to: type=gha,mode=max + + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: ${{ inputs.BUILD_DIR }} + file: ${{ inputs.BUILD_DIR }}/Dockerfile + # These arguments get passed into the docker image itself + build-args: | + TX_DOCKER_VERSION=${{ github.sha }} + TX_RELEASE_TAG=dev-${{ steps.release_info.outputs.date }} + TX_RELEASE_DATE=${{ steps.release_info.outputs.date }} + push: true + # We use three tags for release builds: + # txpipe-dev + # txpipe-dev:latest + # txpipe-dev: + tags: ${{ inputs.PUSH_TAG }},${{ inputs.PUSH_TAG }}:latest,${{ inputs.PUSH_TAG }}:${{ steps.release_info.outputs.date }},${{ inputs.PUSH_TAG }}:${{ github.sha }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/build-dev-image.yml b/.github/workflows/build-dev-image.yml index bcc65c2..5ce5bd7 100644 --- a/.github/workflows/build-dev-image.yml +++ b/.github/workflows/build-dev-image.yml @@ -2,81 +2,14 @@ name: Build Developer Image on: workflow_dispatch -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - BUILD_DIR: ./txpipe-dev - TEST_TAG: lsstdesc/txpipe-dev:testing - PUSH_TAG: ghcr.io/lsstdesc/txpipe-dev - # Set this to 0 to - DO_TEST: ${{ false }} jobs: build: name: Build Developer Image - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Log in to the Container registry - uses: docker/login-action@v3 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v3 - - # This only gets the date in this job, because - # there is no release tag - - name: Get release info - id: release_info - run: | - echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT - - - name: Build docker image - uses: docker/build-push-action@v5 - with: - context: ${{ env.BUILD_DIR }} - file: ${{ env.BUILD_DIR }}/Dockerfile - # the load option means the built image is kept locally - # but not pushed yet - load: true - build-args: | - TX_DOCKER_VERSION=${{ github.sha }} - TX_RELEASE_TAG=dev-${{ steps.release_info.outputs.date }} - TX_RELEASE_DATE=${{ steps.release_info.outputs.date }} - tags: ${{ env.TEST_TAG }} - cache-from: type=gha - cache-to: type=gha,mode=max - - # - name: Test docker image - # if: ${{ env.DO_TEST }} - # run: | - # docker run -v $PWD/test:/opt/TXPipe --rm -t ${{ env.TEST_TAG }} /opt/TXPipe/test-image.sh - - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: ${{ env.BUILD_DIR }} - file: ${{ env.BUILD_DIR }}/Dockerfile - # These arguments get passed into the docker image itself - build-args: | - TX_DOCKER_VERSION=${{ github.sha }} - TX_RELEASE_TAG=dev-${{ steps.release_info.outputs.date }} - TX_RELEASE_DATE=${{ steps.release_info.outputs.date }} - push: true - # We use three tags for release builds: - # txpipe-dev - # txpipe-dev:latest - # txpipe-dev: - tags: ${{ env.PUSH_TAG}},${{ env.PUSH_TAG}}:latest,${{ env.PUSH_TAG}}:${{ steps.release_info.outputs.date }} - cache-from: type=gha - cache-to: type=gha,mode=max + uses: ./.github/workflows/build-an-image.yml + with: + IMAGE_NAME: ${{ github.repository }} + BUILD_DIR: ./txpipe-dev + TEST_TAG: lsstdesc/txpipe-dev:testing + PUSH_TAG: ghcr.io/lsstdesc/txpipe-dev diff --git a/.github/workflows/build-production-image.yml b/.github/workflows/build-production-image.yml index acd1403..0424403 100644 --- a/.github/workflows/build-production-image.yml +++ b/.github/workflows/build-production-image.yml @@ -4,57 +4,13 @@ on: release: types: [published] -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - - jobs: build: name: Build Production Image - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Log in to the Container registry - uses: docker/login-action@v2 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v2 - - # Save the date and tag name for this release - # as variables - - name: Get release info - id: release_info - run: | - echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT - echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT - - - name: Build and push Docker image - uses: docker/build-push-action@v4 - with: - context: ./txpipe - file: ./txpipe/Dockerfile - # These arguments get passed into the docker image itself - build-args: | - TX_DOCKER_VERSION=${{ github.sha }} - TX_RELEASE_DATE=${{ steps.release_info.outputs.date }} - TX_RELEASE_TAG=${{ steps.release_info.outputs.tag }} - push: true - # We use four tags for release builds: - # txpipe - # txpipe:latest - # txpipe: - # txpipe: - tags: ghcr.io/lsstdesc/txpipe,ghcr.io/lsstdesc/txpipe:latest,ghcr.io/lsstdesc/txpipe:${{ steps.release_info.outputs.date }},ghcr.io/lsstdesc/txpipe:${{ steps.release_info.outputs.tag }} - cache-from: type=gha - cache-to: type=gha,mode=max + uses: ./.github/workflows/build-an-image.yml + with: + IMAGE_NAME: ${{ github.repository }} + BUILD_DIR: ./txpipe + TEST_TAG: lsstdesc/txpipe:latest + PUSH_TAG: ghcr.io/lsstdesc/txpipe + \ No newline at end of file