尝试gitea action
Some checks failed
Build and Push Docker Images / build-and-push (backend) (push) Failing after 1m4s
Build and Push Docker Images / build-and-push (frontend) (push) Has been cancelled

This commit is contained in:
小贺
2025-09-03 19:11:50 +08:00
parent a0e58acb46
commit f0e4249312
2 changed files with 67 additions and 27 deletions

View File

@@ -1,29 +1,73 @@
name: Build and Push Docker Image
name: Build and Push Docker Images
on:
push:
branches:
- main
branches: [ main ]
tags: [ 'v*' ]
pull_request:
branches: [ main ]
jobs:
build-and-push:
runs-on: ubuntu-latest
strategy:
matrix:
service: [frontend, backend]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to Registry
uses: docker/login-action@v3
with:
registry: gitea.zfxt.top
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.AUTH_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: your-dockerhub-username/your-repo-name:latest
- name: Extract metadata for backend
if: matrix.service == 'backend'
id: meta-backend
uses: docker/metadata-action@v5
with:
images: gitea.zfxt.top/zfxt/backend
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Extract metadata for frontend
if: matrix.service == 'frontend'
id: meta-frontend
uses: docker/metadata-action@v5
with:
images: gitea.zfxt.top/zfxt/frontend
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push backend image
if: matrix.service == 'backend'
uses: docker/build-push-action@v5
with:
context: ./backend
file: ./backend/dockerfile
push: true
tags: ${{ steps.meta-backend.outputs.tags }}
labels: ${{ steps.meta-backend.outputs.labels }}
- name: Build and push frontend image
if: matrix.service == 'frontend'
uses: docker/build-push-action@v5
with:
context: ./front
file: ./front/dockerfile
push: true
tags: ${{ steps.meta-frontend.outputs.tags }}
labels: ${{ steps.meta-frontend.outputs.labels }}

View File

@@ -2,26 +2,22 @@ version: '3.8'
services:
frontend:
build:
context: ./front
dockerfile: dockerfile
container_name: my-frontend-web
image: gitea.zfxt.top/zfxt/frontend:latest
container_name: my-frontend-web
ports:
- "5555:5555" # 修改为5555端口映射
- "5555:5555"
depends_on:
- backend
networks:
- app-network
# 移除了build配置因为我们现在使用预构建的镜像
backend:
build:
context: ./backend
dockerfile: dockerfile
image: gitea.zfxt.top/zfxt/backend:latest
container_name: my-backend-api # 设置后端容器名
container_name: my-backend-api
networks:
- app-network
# 移除了build配置因为我们现在使用预构建的镜像
networks:
app-network: