-
Notifications
You must be signed in to change notification settings - Fork 2
87 lines (84 loc) · 2.95 KB
/
release_deploy.yml
File metadata and controls
87 lines (84 loc) · 2.95 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
name: Release and Deploy
on:
push:
branches: [main]
paths:
- "package.json"
- "package-lock.json"
- "tsconfig.json"
- "src/**"
- "deployment.yml"
- "Dockerfile"
- ".github/workflows/release_deploy.yml"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
- name: Cache node modules
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install dependencies
run: "npm ci --ignore-scripts"
- name: Build
run: "tsc"
- name: Release
uses: getsentry/action-release@v3
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
environment: production
sourcemaps: "./target"
url_prefix: "~/target"
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Build container image
run: docker build -t ${{ secrets.DIGITALOCEAN_IMAGE_URL }}:$(echo $GITHUB_SHA | head -c7) .
- name: Log in to registry
run: doctl registry login --expiry-seconds 1200
- name: Push image to registry
run: docker push ${{ secrets.DIGITALOCEAN_IMAGE_URL }}:$(echo $GITHUB_SHA | head -c7)
- name: Update deployment file
run: TAG=$(echo $GITHUB_SHA | head -c7) && sed -i -e 's|<IMAGE>|${{ secrets.DIGITALOCEAN_IMAGE_URL }}:'${TAG}'|' -e 's|<RELEASE_HASH>|'${GITHUB_SHA}'|' $GITHUB_WORKSPACE/deployment.yml
- name: Save kubeconfig
run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 ${{ secrets.DIGITALOCEAN_CLUSTER_NAME }}
- name: Deploy using kubectl
run: kubectl apply -f $GITHUB_WORKSPACE/deployment.yml
- name: Verify deployment
run: |
if ! kubectl rollout status statefulset/formula-one -n formulaone; then
echo "Deployment failed, rolling back..."
kubectl rollout undo deployment/formula-one -n formulaone
exit 1
fi
- name: Remove old images from registry
uses: ripplr-io/docr-image-remove@73f900f94464879edf44ba8d0a75d596d826ad7f
with:
image_repository: formula-one
buffer_size: 3