Add: CI/CD workflows for Docker build
Build and Push Docker Image / build_docker_image (push) Failing after 3m39s
Build and Push Docker Image / build_docker_image (push) Failing after 3m39s
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
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-relay # 你的 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 生成的标签
|
||||
cache-from: type=gha # 启用 GitHub Actions 缓存构建层
|
||||
cache-to: type=gha,mode=max # 将构建层写入缓存
|
||||
Reference in New Issue
Block a user