-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (88 loc) · 3.47 KB
/
CICD When Release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: CICD When Release.yml
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
services:
docker:
image: docker:latest
options: --privileged
ports:
- 80:80
- 8000:8000
- 3000:3000
volumes:
- /var/run/docker.sock:/var/run/docker.sock
steps:
- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
docker-compose --version
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# 构建单架构后端服务镜像用于本地测试
- name: Build backend service image for testing
run: docker build -t backend:test -f ./Django/Dockerfile ./Django
# 构建单架构前端服务镜像用于本地测试
- name: Build web service image for testing
run: docker build -t web:test -f ./astro/Dockerfile ./astro
# # 构建单架构 Nginx 服务镜像用于本地测试
# - name: Build nginx service image for testing
# run: docker build -t nginx:test -f ./nginx/nginx.Dockerfile .
# 启动 Docker Compose 服务用于测试
- name: Start Docker Compose services for testing
run: docker compose -f "./GitHub Action Build Docker.yml" up --build -d
- name: Wait for services to be up
run: |
echo "Waiting for services to be up..."
sleep 6
- name: Run tests
run: |
curl -f http://localhost:3000
curl -f http://localhost:3000/posts/1
curl -f http://localhost:3000/archive
curl -f http://localhost:3000/about
curl -f http://localhost:8000/api/posts/
curl -f http://localhost:8000/admin/
# 构建并推送多架构后端服务镜像
- name: Build and push multi-arch backend service image
if: success()
uses: docker/build-push-action@v2
with:
context: ./Django
file: ./Django/Dockerfile
tags: ${{ secrets.DOCKER_USERNAME }}/appleblog_backend:latest,${{ secrets.DOCKER_USERNAME }}/appleblog_backend:${{ github.event.release.tag_name }}
platforms: linux/amd64,linux/arm64
push: true
# 构建并推送多架构前端服务镜像
- name: Build and push multi-arch web service image
if: success()
uses: docker/build-push-action@v2
with:
context: ./astro
file: ./astro/Dockerfile
tags: ${{ secrets.DOCKER_USERNAME }}/appleblog_web:latest,${{ secrets.DOCKER_USERNAME }}/appleblog_web:${{ github.event.release.tag_name }}
platforms: linux/amd64,linux/arm64
push: true
# # 构建并推送多架构 Nginx 服务镜像
# - name: Build and push multi-arch nginx service image
# if: success()
# uses: docker/build-push-action@v2
# with:
# context: ./
# file: ./nginx/nginx.Dockerfile
# tags: ${{ secrets.DOCKER_USERNAME }}/appleblog_nginx:latest,${{ secrets.DOCKER_USERNAME }}/appleblog_nginx:${{ github.event.release.tag_name }}
# platforms: linux/amd64,linux/arm64
# push: true