Skip to content

Commit

Permalink
Unify production and test image builder jobs in one
Browse files Browse the repository at this point in the history
  • Loading branch information
joezuntz committed Jun 19, 2024
1 parent 63d9d89 commit 4c8fe2b
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 124 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/build-an-image.yml
Original file line number Diff line number Diff line change
@@ -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:<the date, e.g. 2023-03-21>
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
79 changes: 6 additions & 73 deletions .github/workflows/build-dev-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:<the date, e.g. 2023-03-21>
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
58 changes: 7 additions & 51 deletions .github/workflows/build-production-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:<the date, e.g. 2023-03-21>
# txpipe:<the release tag, e.g. v0.3>
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

0 comments on commit 4c8fe2b

Please sign in to comment.