Skip to content

V1.0.2 2024/7/12

V1.0.2 2024/7/12 #7

name: CICD When Release.yml
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
services:
docker:
image: docker:19.03.12
options: --privileged
ports:
- 80:80
- 8000:8000
- 3000:3000
volumes:
- /var/run/docker.sock:/var/run/docker.sock
steps:
- 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