ci: docker镜像构建 #30
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: Docker | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- 'v*' | |
env: | |
APP_NAME: ${{ github.event.repository.name }} | |
NAMESPACE: app | |
REGISTRY: ${{ secrets.DOCKER_REGISTRY && secrets.DOCKER_REGISTRY || 'docker.io' }} | |
REPOSITORY: ${{ github.repository }} | |
IMAGE_LATEST_TAG: ${{ startsWith(github.ref, 'refs/tags/') && 'latest' || 'main' }} | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
goos: [ linux ] | |
goarch: [ "386", amd64, arm, arm64 ] | |
exclude: | |
- goos: darwin | |
goarch: arm | |
- goos: darwin | |
goarch: "386" | |
fail-fast: true | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set environment variables | |
run: | | |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then | |
VERSION_TAG=${GITHUB_REF#refs/tags/} | |
else | |
VERSION_TAG=${IMAGE_LATEST_TAG} | |
fi | |
echo "VERSION_TAG=${VERSION_TAG}" >> $GITHUB_ENV | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: '1.22' | |
- name: Mkdir | |
run: | | |
mkdir -p ./frontend/dist | |
echo "" > ./frontend/dist/index.html | |
- name: Lint | |
uses: golangci/golangci-lint-action@v6 | |
- name: Tests | |
run: | | |
go test $(go list ./...) | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_TOKEN }} | |
- name: Prepare | |
run: | | |
platform=${{ matrix.platform }} | |
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV | |
- name: Docker build and push | |
uses: docker/build-push-action@v5 | |
with: | |
platforms: ${{ matrix.platform }} | |
push: true | |
file: Dockerfile | |
# 如果IMAGE_TAG为空,则使用${{ steps.vars.outputs.sha_short }} | |
tags: codfrm/dns-kit:${{ env.IMAGE_LATEST_TAG }},codfrm/dns-kit:${{ env.VERSION_TAG }} | |
context: . |