From 3959d10a65c26ee7ce7e22a23c9e9cde0317e336 Mon Sep 17 00:00:00 2001 From: templari Date: Sun, 22 Oct 2023 10:18:27 +0800 Subject: [PATCH] Update pipeline --- .github/workflows/main.yml | 51 +++++++++++++++++++++++++++----------- Dockerfile | 13 ++++++++++ nginx.conf | 9 +++++++ 3 files changed, 59 insertions(+), 14 deletions(-) create mode 100644 Dockerfile create mode 100644 nginx.conf diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d0821d5..ed124a8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,6 +3,12 @@ on: push: branches: - v2 + +env: + REGISTRY: ghcr.io + IMAGE_NAME: sunday + IMAGE_NAME_FULL: ghcr.io/nbtca/sunday + jobs: build: runs-on: ubuntu-latest @@ -10,18 +16,35 @@ jobs: # 切换分支 - name: Checkout uses: actions/checkout@master - - uses: actions/setup-node@v2 + + - name: Login DockerHub + uses: docker/login-action@v2 with: - node-version: "16" - - run: npm install - - run: npm run build - # Deploy - - name: ssh deploy - uses: easingthemes/ssh-deploy@v2.2.11 - env: - SSH_PRIVATE_KEY: ${{ secrets.ACCESS_TOKEN }} - ARGS: "-avz --delete" - SOURCE: "dist/" - REMOTE_HOST: ${{ secrets.REMOTE_HOST }} - REMOTE_USER: ${{ secrets.REMOTE_USER }} - TARGET: "/home/nbtca/weekend/web/v2" + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and Push to DockerHub + uses: docker/build-push-action@v3 + with: + context: . + file: ./Dockerfile + no-cache: true + # target: deploy + push: true + platforms: linux/amd64 + tags: | + ${{ env.IMAGE_NAME_FULL }}:latest + + - name: ssh pipelines + uses: cross-the-world/ssh-pipeline@master + with: + host: ${{ secrets.REMOTE_HOST }} + user: ${{ secrets.REMOTE_USER }} + key: ${{ secrets.ACCESS_TOKEN }} + connect_timeout: 10s + script: | + cd /home/nbtca/weekend/sunday + docker-compose stop && docker-compose rm -f + docker rmi ${{ env.IMAGE_NAME_FULL }}:latest + docker-compose up -d \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6f085e4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM node as build + +COPY . /app +WORKDIR /app + +RUN npm install &&\ + npm run build + + +FROM nginx:alpine as deploy + +COPY nginx.conf /etc/nginx/conf.d/default.conf +COPY --from=build /app/dist /usr/share/nginx/html \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..9e43d4b --- /dev/null +++ b/nginx.conf @@ -0,0 +1,9 @@ +server { + listen 80; + server_name frontend; + + location / { + root /usr/share/nginx/html; + try_files $uri $uri/ /index.html; + } +} \ No newline at end of file