Files
2026-10-04 18:19:52 +08:00

63 lines
1.8 KiB
YAML

name: Build and Deploy
on:
push:
tags:
- '*'
env:
APP_IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/daoyou-app
jobs:
build-and-push:
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Image tags and revision
id: metadata
uses: docker/metadata-action@v5
with:
images: ${{ env.APP_IMAGE_NAME }}
tags: |
type=ref,event=tag
type=sha,format=long
type=raw,value=latest
# 登录 Docker Hub
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push app image
id: build
uses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile.app
push: true
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
# Share intermediate build layers across release tags.
cache-from: type=registry,ref=${{ env.APP_IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.APP_IMAGE_NAME }}:buildcache,mode=max
- name: Record release identity
env:
IMAGE_DIGEST: ${{ steps.build.outputs.digest }}
IMAGE_TAGS: ${{ steps.metadata.outputs.tags }}
run: |
{
printf 'Revision: `%s`\n\n' "$GITHUB_SHA"
printf 'Release tag: `%s`\n\n' "$GITHUB_REF_NAME"
printf 'Image digest: `%s`\n\n' "$IMAGE_DIGEST"
printf 'Image tags:\n```text\n%s\n```\n' "$IMAGE_TAGS"
} >> "$GITHUB_STEP_SUMMARY"