Skip to content

Commit 3959d10

Browse files
committed
Update pipeline
1 parent 616964d commit 3959d10

File tree

3 files changed

+59
-14
lines changed

3 files changed

+59
-14
lines changed

.github/workflows/main.yml

+37-14
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,48 @@ on:
33
push:
44
branches:
55
- v2
6+
7+
env:
8+
REGISTRY: ghcr.io
9+
IMAGE_NAME: sunday
10+
IMAGE_NAME_FULL: ghcr.io/nbtca/sunday
11+
612
jobs:
713
build:
814
runs-on: ubuntu-latest
915
steps:
1016
# 切换分支
1117
- name: Checkout
1218
uses: actions/checkout@master
13-
- uses: actions/setup-node@v2
19+
20+
- name: Login DockerHub
21+
uses: docker/login-action@v2
1422
with:
15-
node-version: "16"
16-
- run: npm install
17-
- run: npm run build
18-
# Deploy
19-
- name: ssh deploy
20-
uses: easingthemes/[email protected]
21-
env:
22-
SSH_PRIVATE_KEY: ${{ secrets.ACCESS_TOKEN }}
23-
ARGS: "-avz --delete"
24-
SOURCE: "dist/"
25-
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
26-
REMOTE_USER: ${{ secrets.REMOTE_USER }}
27-
TARGET: "/home/nbtca/weekend/web/v2"
23+
registry: ${{ env.REGISTRY }}
24+
username: ${{ github.actor }}
25+
password: ${{ secrets.GITHUB_TOKEN }}
26+
27+
- name: Build and Push to DockerHub
28+
uses: docker/build-push-action@v3
29+
with:
30+
context: .
31+
file: ./Dockerfile
32+
no-cache: true
33+
# target: deploy
34+
push: true
35+
platforms: linux/amd64
36+
tags: |
37+
${{ env.IMAGE_NAME_FULL }}:latest
38+
39+
- name: ssh pipelines
40+
uses: cross-the-world/ssh-pipeline@master
41+
with:
42+
host: ${{ secrets.REMOTE_HOST }}
43+
user: ${{ secrets.REMOTE_USER }}
44+
key: ${{ secrets.ACCESS_TOKEN }}
45+
connect_timeout: 10s
46+
script: |
47+
cd /home/nbtca/weekend/sunday
48+
docker-compose stop && docker-compose rm -f
49+
docker rmi ${{ env.IMAGE_NAME_FULL }}:latest
50+
docker-compose up -d

Dockerfile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM node as build
2+
3+
COPY . /app
4+
WORKDIR /app
5+
6+
RUN npm install &&\
7+
npm run build
8+
9+
10+
FROM nginx:alpine as deploy
11+
12+
COPY nginx.conf /etc/nginx/conf.d/default.conf
13+
COPY --from=build /app/dist /usr/share/nginx/html

nginx.conf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
server {
2+
listen 80;
3+
server_name frontend;
4+
5+
location / {
6+
root /usr/share/nginx/html;
7+
try_files $uri $uri/ /index.html;
8+
}
9+
}

0 commit comments

Comments
 (0)