Skip to content

build-image-manual

build-image-manual #92

name: build-image-manual
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
on:
workflow_dispatch:
inputs:
project:
description: 'Project name'
required: true
type: choice
options:
- coder-development
- epay
- dujiaoka
- fluentd
- helmfile
- opsutils
- tidb-toolkit
- jenkins
- subconverter
- frps
- vmianqian
- tokenpay
- n8n
- forwardpanel
tag:
description: 'Image tag'
env:
PROJECT_NAME: ${{ github.event.inputs.project }}
# github.repository as <account>/<repo>
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set tag
id: tag
run: |
tag=""
dockerfile_version=$(cat ${{ env.PROJECT_NAME }}/Dockerfile | awk '{if($1~"LABEL" && $2=="VERSION")print $3}')
if [[ -n "${{ github.event.inputs.tag }}" ]]; then
tag=${{ github.event.inputs.tag }}
elif [[ -n "${dockerfile_version}" ]]; then
tag=${dockerfile_version}
else
echo "Image tag can not be null!"
exit 1
fi
docker_image_name=${{ secrets.DOCKER_USERNAME }}/${{ env.PROJECT_NAME }}
tags=${docker_image_name}:${tag},${docker_image_name}:latest
echo "IMAGE_TAGS=${tags}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-${{ env.PROJECT_NAME }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ env.PROJECT_NAME }}-
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/[email protected]
with:
context: ${{ env.PROJECT_NAME }}
push: true
tags: ${{ env.IMAGE_TAGS }}
platforms: linux/amd64,linux/arm64
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Check readme existence
id: check_files
uses: andstor/file-existence-action@v1
with:
files: "${{ env.PROJECT_NAME }}/README.md"
- name: Sync README.md to Docker Hub
if: steps.check_files.outputs.files_exists == 'true'
uses: ms-jpq/sync-dockerhub-readme@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: ${{ secrets.DOCKER_USERNAME }}/${{ env.PROJECT_NAME }}
readme: "${{ env.PROJECT_NAME }}/README.md"