Files
nostr-relay/.github/workflows/docker.yml
T
laoxong 14ee46a24b
Build and Push Docker Image / build_docker_image (push) Successful in 8m9s
Remove Docker cache configuration
2025-08-04 02:43:09 +08:00

56 lines
1.8 KiB
YAML

name: Build and Push Docker Image
on:
push:
branches:
- master
- develop
pull_request:
branches:
- master
- develop
workflow_dispatch:
jobs:
build_docker_image:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
# 只有当你的 DOCKER_USERNAME 存在时才执行此步骤
if: secrets.DOCKER_USERNAME != ''
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract Docker metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKER_USERNAME }}/nostr_demo # 你的 Docker Hub 仓库名称,替换为你的用户名
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,format=long,prefix=
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' }} # main/master 分支打 latest 标签
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' }} # 只有在非 PR 事件时才推送
tags: ${{ steps.meta.outputs.tags }} # 使用 docker/metadata-action 生成的标签
labels: ${{ steps.meta.outputs.labels }} # 使用 docker/metadata-action 生成的标签