Skip to content

Docker-Publish

Docker-Publish #122

name: Docker-Publish
on:
schedule:
# Recompile at 00:15 UTC on Sundays
- cron: '15 0 * * 0'
push:
# Publish `main` as Docker `latest` image.
branches:
- main
# Publish `v1.2.3` tags as releases.
tags:
- v*
workflow_dispatch:
# Allow this event to be triggered in the github ui
env:
IMAGE_NAME: tensorflow-build
jobs:
get-version:
runs-on: ubuntu-latest
steps:
- id: version
run: |
# Get the latest version of tensorflow
export TENSORFLOW_COMMIT=$(git ls-remote https://github.com/tensorflow/tensorflow.git HEAD | awk '{ print substr($1, 1, 8)}'D)
echo "tensorflow_commit=${TENSORFLOW_COMMIT}" >>$GITHUB_OUTPUT
outputs:
tensorflow_commit: ${{ steps.version.outputs.tensorflow_commit }}
# Push image to GitHub Packages.
build:
needs: [get-version]
strategy:
matrix:
arch: [ { runson: ubuntu-large-disk-space, id: -amd64 } ]
#arch: [ { runson: ARM64, id: -arm64 }, { runson: ubuntu-large-disk-space, id: -amd64 } ] # disabling arm64 until we can figure out either new machines to run these on or wipe/ reset Matt's old ones -klb
runs-on: ${{ matrix.arch.runson }}
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: checkout code
uses: actions/checkout@v3
- name: Log into registry
run: echo "${{ secrets.CR_PAT }}" | docker login ghcr.io -u ${{ secrets.DOCKER_USER }} --password-stdin
- name: Build image
run: |
# define the image id
IMAGE_ID=ghcr.io/${{ github.repository }}/$IMAGE_NAME${{matrix.arch.id}}
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
echo IMAGE_ID=$IMAGE_ID
echo VERSION=${{ needs.get-version.outputs.tensorflow_commit}}
echo ARCH=${{matrix.arch.id}}
# Build the image
docker buildx build .\
--provenance false \
--build-arg COMMIT_HASH=${{ needs.get-version.outputs.tensorflow_commit}} \
--push \
--tag $IMAGE_ID:${{ needs.get-version.outputs.tensorflow_commit}} \
--file Dockerfile \
# Push the latest tag if everything build
push-latest:
needs: [get-version, build]
runs-on: ubuntu-latest
strategy:
max-parallel: 1
matrix:
arch: [ { runson: ubuntu-latest, id: -amd64 } ]
#arch: [ { runson: ARM64, id: -arm64 }, { runson: ubuntu-latest, id: -amd64 } ]
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- uses: actions/checkout@v3
- name: Log into registry
run: echo "${{ secrets.CR_PAT }}" | docker login ghcr.io -u ${{ secrets.DOCKER_USER }} --password-stdin
- uses: actions/setup-go@v3
with:
go-version: '>=1.18.10'
- name: Build Manifest Tool
run: |
git clone https://github.com/estesp/manifest-tool
cd manifest-tool && make binary
cd ..
- name: Build Manifest
run: |
export TF_VERSION=${{ needs.get-version.outputs.tensorflow_commit}}
# Define the base image id
IMAGE_ID=ghcr.io/${{ github.repository }}/$IMAGE_NAME
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# check if image exisits
if docker manifest inspect $IMAGE_ID:$TF_VERSION > /dev/null; then
echo "Appending manifest"
docker buildx imagetools create -t $IMAGE_ID:$TF_VERSION --append $IMAGE_ID${{matrix.arch.id}}:$TF_VERSION
docker buildx imagetools create -t $IMAGE_ID:latest --append $IMAGE_ID${{matrix.arch.id}}:$TF_VERSION
else
echo "Creating new manifest"
docker buildx imagetools create -t $IMAGE_ID:$TF_VERSION $IMAGE_ID${{matrix.arch.id}}:$TF_VERSION
docker buildx imagetools create -t $IMAGE_ID:latest $IMAGE_ID${{matrix.arch.id}}:$TF_VERSION
fi
trigger-event:
needs: push-latest
runs-on: ubuntu-latest
steps:
- name: Repository Dispatch to rebuild ABLATE dependcies
uses: peter-evans/repository-dispatch@v2
with:
repository: UBCHREST/ablate
token: ${{ secrets.TRIGGER_PAT }}
event-type: rebuild-dependencies