Skip to content

Build and Publish Docker Image #3

Build and Publish Docker Image

Build and Publish Docker Image #3

Workflow file for this run

name: Build and Publish Docker Image
on:
workflow_dispatch:
env:
GHCR_IMAGE: ghcr.io/hackycy/hackycy-cli
TENCENT_IMAGE: ccr.ccs.tencentyun.com/sooosin/hackycy-cli
PLATFORMS: linux/amd64,linux/arm64
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Verify selected ref is a release tag
if: github.ref_type != 'tag'
run: |
echo 'Run this workflow from a release tag, for example v0.0.62.' >&2
exit 1
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Download Linux binaries from GitHub Release
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ github.ref_name }}
run: |
mkdir -p release-assets docker-artifacts/ycy-linux-x64 docker-artifacts/ycy-linux-arm64
gh release download "$RELEASE_TAG" \
--repo "$GITHUB_REPOSITORY" \
--pattern ycy-linux-x64 \
--pattern ycy-linux-arm64 \
--dir release-assets
mv release-assets/ycy-linux-x64 docker-artifacts/ycy-linux-x64/ycy-linux-x64
mv release-assets/ycy-linux-arm64 docker-artifacts/ycy-linux-arm64/ycy-linux-arm64
chmod +x docker-artifacts/ycy-linux-*/ycy-linux-*
- name: Resolve image tags
id: image
env:
TAG: ${{ github.ref_name }}
GHCR_IMAGE: ${{ env.GHCR_IMAGE }}
TENCENT_IMAGE: ${{ env.TENCENT_IMAGE }}
run: |
{
echo 'tags<<EOF'
echo "$GHCR_IMAGE:$TAG"
echo "$TENCENT_IMAGE:$TAG"
echo 'EOF'
} >> "$GITHUB_OUTPUT"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Tencent Cloud Container Registry
uses: docker/login-action@v3
with:
registry: ccr.ccs.tencentyun.com
username: ${{ secrets.TENCENT_USERNAME }}
password: ${{ secrets.TENCENT_PASSWORD }}
- name: Build and publish image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
platforms: ${{ env.PLATFORMS }}
push: true
tags: ${{ steps.image.outputs.tags }}
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
cache-from: |
type=gha,scope=ghcr-hackycy-cli
type=gha,scope=tencent-hackycy-cli
cache-to: |
type=gha,mode=max,scope=ghcr-hackycy-cli
type=gha,mode=max,scope=tencent-hackycy-cli