ci: docker镜像构建 #25
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 }} | |
# 判断是否是tag,是的话就使用tag作为版本号,否则使用branch | |
IMAGE_TAG: ${{ startsWith(github.ref, 'refs/tags/') && github.ref || '' }} | |
IMAGE_LATEST_TAG: ${{ startsWith(github.ref, 'refs/tags/') && 'latest' || 'main' }} | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
# build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/amd64, darwin/arm64 | |
goos: [linux, darwin] | |
goarch: ["386", amd64, arm, arm64] | |
exclude: | |
- goos: darwin | |
goarch: arm | |
- goos: darwin | |
goarch: "386" | |
fail-fast: true | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
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: Set outputs | |
id: vars | |
run: | | |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
- name: Docker build and push | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
file: Dockerfile | |
# 如果IMAGE_TAG为空,则使用${{ steps.vars.outputs.sha_short }} | |
tags: codfrm/dns-kit:${{ env.IMAGE_LATEST_TAG }},codfrm/dns-kit:${{ env.IMAGE_TAG && env.IMAGE_TAG || steps.vars.outputs.sha_short }} | |
context: . |