|
| 1 | +name: Build & Push Docker Images on Tag |
| 2 | +on: |
| 3 | + push: |
| 4 | + tags: |
| 5 | + - 'v*' # Triggers only on tags like v0.1.2, v0.1.2.dev1, etc. |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + build-and-push: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + env: |
| 12 | + IMAGE_BASE: isisacceleratorcontrols/poly-lithic |
| 13 | + steps: |
| 14 | + - name: Checkout repository |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Extract version from tag |
| 18 | + id: vars |
| 19 | + run: | |
| 20 | + TAG_NAME=${GITHUB_REF#refs/tags/} |
| 21 | + echo "VERSION=${TAG_NAME}" >> $GITHUB_ENV |
| 22 | + echo "version=${TAG_NAME}" >> $GITHUB_OUTPUT |
| 23 | +
|
| 24 | + - name: Log in to Docker Hub |
| 25 | + uses: docker/login-action@v3 |
| 26 | + with: |
| 27 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 28 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 29 | + |
| 30 | + - name: Build Docker images with version injection |
| 31 | + run: | |
| 32 | + docker build --pull --rm --target vanilla \ |
| 33 | + --build-arg VERSION=${VERSION} \ |
| 34 | + -f Dockerfile -t $IMAGE_BASE:base-${VERSION} . |
| 35 | +
|
| 36 | + docker build --pull --rm --target torch \ |
| 37 | + --build-arg VERSION=${VERSION} \ |
| 38 | + -f Dockerfile -t $IMAGE_BASE:torch-${VERSION} . |
| 39 | +
|
| 40 | + docker build --pull --rm --target tensorflow \ |
| 41 | + --build-arg VERSION=${VERSION} \ |
| 42 | + -f Dockerfile -t $IMAGE_BASE:tensorflow-${VERSION} . |
| 43 | +
|
| 44 | + - name: Push versioned images |
| 45 | + run: | |
| 46 | + docker push $IMAGE_BASE:base-${VERSION} |
| 47 | + docker push $IMAGE_BASE:torch-${VERSION} |
| 48 | + docker push $IMAGE_BASE:tensorflow-${VERSION} |
| 49 | +
|
| 50 | + - name: Tag and push latest if version is pure semver |
| 51 | + if: ${{ steps.vars.outputs.version =~ '^v[0-9]+\\.[0-9]+\\.[0-9]+$' }} |
| 52 | + run: | |
| 53 | + echo "Tag is a pure semver release — tagging latest" |
| 54 | +
|
| 55 | + docker tag $IMAGE_BASE:base-${VERSION} $IMAGE_BASE:base-latest |
| 56 | + docker tag $IMAGE_BASE:torch-${VERSION} $IMAGE_BASE:torch-latest |
| 57 | + docker tag $IMAGE_BASE:tensorflow-${VERSION} $IMAGE_BASE:tensorflow-latest |
| 58 | + docker tag $IMAGE_BASE:base-latest $IMAGE_BASE:latest |
| 59 | +
|
| 60 | + docker push $IMAGE_BASE:base-latest |
| 61 | + docker push $IMAGE_BASE:torch-latest |
| 62 | + docker push $IMAGE_BASE:tensorflow-latest |
| 63 | + docker push $IMAGE_BASE:latest |
0 commit comments