From e8257ff1e9697eb8c8f09c771142ef8a43e91228 Mon Sep 17 00:00:00 2001 From: zhaoyingbo Date: Wed, 6 Mar 2024 09:26:21 +0000 Subject: [PATCH] =?UTF-8?q?ci:=20=E6=96=B0=E5=A2=9ECICD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/cicd.yaml | 57 ++++++++++++++++++++++++++++++++++++++ Dockerfile | 13 +++++++++ docker-compose.yml | 7 +++++ 3 files changed, 77 insertions(+) create mode 100644 .gitea/workflows/cicd.yaml create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.gitea/workflows/cicd.yaml b/.gitea/workflows/cicd.yaml new file mode 100644 index 0000000..216ee74 --- /dev/null +++ b/.gitea/workflows/cicd.yaml @@ -0,0 +1,57 @@ +name: CI Monitor CI/CD +on: [push] + +jobs: + build-image: + runs-on: ubuntu-latest + container: catthehacker/ubuntu:act-latest + steps: + - name: Check out repository code + uses: actions/checkout@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + registry: git.yingbo.im:333 + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Build and push + uses: docker/build-push-action@v4 + with: + push: true + tags: git.yingbo.im:333/zhaoyingbo/ci_monitor:${{ github.sha }} + + deploy: + needs: build-image + runs-on: ubuntu-latest + container: catthehacker/ubuntu:act-latest + steps: + # 检出代码 + - name: Check out repository code + uses: actions/checkout@v3 + # 使用scp命令将docker-compose.yml文件上传到服务器 + - name: Upload docker-compose.yml to server + uses: appleboy/scp-action@master + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USERNAME }} + key: ${{ secrets.SERVER_KEY }} + port: ${{ secrets.SERVER_PORT }} + source: docker-compose.yml + target: /home/${{ secrets.SERVER_USERNAME }}/docker/ci_monitor + # 登录服务器,执行docker-compose命令 + - name: Login to the server and execute docker-compose command + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USERNAME }} + key: ${{ secrets.SERVER_KEY }} + port: ${{ secrets.SERVER_PORT }} + script: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} git.yingbo.im:333 + cd /home/${{ secrets.SERVER_USERNAME }}/docker/ci_monitor + sed -i "s/sha/${{ github.sha }}/g" docker-compose.yml + docker compose up -d --force-recreate --no-deps ci_monitor diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..90e78e6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM micr.cloud.mioffice.cn/zhaoyingbo/bun:alpine-cn + +WORKDIR /app + +COPY package*.json ./ + +COPY bun.lockb ./ + +RUN bun install + +COPY . . + +CMD ["bun", "start"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..52a3259 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +version: "3" + +services: + ci_monitor: + image: git.yingbo.im:333/zhaoyingbo/ci_monitor:sha + container_name: ci_monitor + restart: always