Build and Push Images #202
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Push Images | |
on: | |
schedule: | |
- cron: '0 22 * * *' | |
release: | |
types: | |
- published | |
workflow_dispatch: | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
dockerhub: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Prepare | |
id: prep | |
run: | | |
DOCKER_IMAGE=${{ secrets.DOCKERHUB_USERNAME }}/${GITHUB_REPOSITORY#*/} | |
ACR_DOCKER_IMAGE="registry.cn-shanghai.aliyuncs.com/${DOCKER_IMAGE}" | |
VERSION=nightly-${GITHUB_SHA::8} | |
# If this is git tag, use the tag name as a docker tag | |
if [[ $GITHUB_REF == refs/tags/* ]]; then | |
VERSION=${GITHUB_REF#refs/tags/v} | |
fi | |
TAGS="${DOCKER_IMAGE}:${VERSION},${ACR_DOCKER_IMAGE}:${VERSION}" | |
# If the VERSION looks like a version number, assume that | |
# this is the most recent version of the image and also | |
# tag it 'latest'. | |
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then | |
TAGS="$TAGS,${DOCKER_IMAGE}:latest,${ACR_DOCKER_IMAGE}:latest" | |
fi | |
# Set output parameters. | |
echo "tags=${TAGS}" >> $GITHUB_OUTPUT | |
echo "docker_image=${DOCKER_IMAGE}" >> $GITHUB_OUTPUT | |
- name: Get image info | |
run: | | |
echo image-tags: ${{ steps.prep.outputs.tags }} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@master | |
with: | |
image: tonistiigi/binfmt:latest | |
platforms: linux/amd64,linux/arm64 | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to DockerHub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Login to Alicloud Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: registry.cn-shanghai.aliyuncs.com | |
username: ${{ secrets.ACR_USERNAME }} | |
password: ${{ secrets.ACR_TOKEN }} | |
- name: Build | |
uses: docker/build-push-action@v3 | |
with: | |
builder: ${{ steps.buildx.outputs.name }} | |
context: . | |
file: ./optools/images/Dockerfile | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ${{ steps.prep.outputs.tags }} | |
ecr: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Prepare | |
id: prep | |
run: | | |
DOCKER_IMAGE=${{ secrets.DOCKERHUB_USERNAME }}/${GITHUB_REPOSITORY#*/} | |
VERSION=nightly-${GITHUB_SHA::8} | |
# If this is git tag, use the tag name as a docker tag | |
if [[ $GITHUB_REF == refs/tags/* ]]; then | |
VERSION=${GITHUB_REF#refs/tags/v} | |
fi | |
# Set output parameters. | |
echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
- name: Get image info | |
run: | | |
echo image-tags: ${{ steps.prep.outputs.version }} | |
# push image to ecr | |
- uses: ./.github/actions/ecr | |
with: | |
role: ${{ secrets.AWS_ROLE }} | |
tag: ${{ steps.prep.outputs.version }} |