-
Notifications
You must be signed in to change notification settings - Fork 1
142 lines (117 loc) Β· 3.81 KB
/
Copy pathdeploy.yml
File metadata and controls
142 lines (117 loc) Β· 3.81 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: Deploy
on:
push:
branches: [main]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
concurrency:
group: production
cancel-in-progress: false
jobs:
test:
name: π§ͺ Test & Build
runs-on: ubuntu-latest
steps:
- name: π₯ Checkout
uses: actions/checkout@v4
- name: π¦ Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.11.0
- name: β‘ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
- name: π§ Install dependencies
run: pnpm install --frozen-lockfile
- name: π Type check
run: pnpm typecheck
- name: ποΈ Build
run: pnpm build
env:
SKIP_ENV_VALIDATION: 1
NEXTAUTH_SECRET: dummy-secret-for-build
NEXTAUTH_URL: https://localhost:3000
DATABASE_URL: postgresql://dummy:dummy@localhost:5432/dummy
YANDEX_STORAGE_ACCESS_KEY: dummy-access-key
YANDEX_STORAGE_SECRET_KEY: dummy-secret-key
YANDEX_STORAGE_BUCKET: dummy-bucket
YANDEX_STORAGE_REGION: ru-central1
build-and-push:
name: π³ Build & Push Image
needs: test
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
image: ${{ steps.meta.outputs.tags }}
digest: ${{ steps.build.outputs.digest }}
steps:
- name: π₯ Checkout
uses: actions/checkout@v4
- name: π§ Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: π Login to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: π·οΈ Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=sha,prefix={{branch}}-
type=raw,value=latest
- name: π Build and push
id: build
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64
deploy:
name: π Deploy to Production
needs: build-and-push
runs-on: ubuntu-latest
environment: production
steps:
- name: π₯ Checkout
uses: actions/checkout@v4
- name: π Setup SSH
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: π Add server to known hosts
run: ssh-keyscan -H ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts
- name: π Copy files to server
run: |
scp -r docker-compose.yml traefik/ monitoring/ postgres/ ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}:~/exterastore/
- name: ποΈ Deploy application
run: |
ssh ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} << 'EOF'
cd ~/exterastore
docker network create traefik-network 2>/dev/null || true
mkdir -p traefik/acme
chmod 600 traefik/acme
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
docker compose down
docker compose pull
docker compose up --build -d
docker image prune -f
EOF
- name: β
Health check
run: |
sleep 30
curl -f https://exterastore.app/api/health