-
Notifications
You must be signed in to change notification settings - Fork 0
139 lines (120 loc) · 4.1 KB
/
Copy pathdeploy.yml
File metadata and controls
139 lines (120 loc) · 4.1 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
# SPDX-FileCopyrightText: 2026 Andrey Kotlyar <[email protected]>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
name: Deploy
on:
push:
branches: [main]
tags:
- "v*.*.*"
permissions:
contents: read
security-events: write
env:
DOCKER_IMAGE: kotlyar562/guitar0net-web
jobs:
build:
name: Build and Push
runs-on: ubuntu-latest
outputs:
version: ${{ steps.meta.outputs.version }}
git_sha: ${{ steps.sha.outputs.short }}
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get short SHA
id: sha
run: echo "short=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
- name: Extract metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.DOCKER_IMAGE }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=staging,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64
pull: true
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ github.ref_name }}
GIT_SHA=${{ steps.sha.outputs.short }}
BUILD_DATETIME=${{ github.run_id }}
NEXT_PUBLIC_API_URL=${{ startsWith(github.ref, 'refs/tags/') && 'https://api.guitar0.net' || 'https://api.staging.guitar0.net' }}
NEXT_PUBLIC_POSTHOG_KEY=${{ vars.NEXT_PUBLIC_POSTHOG_KEY }}
NEXT_PUBLIC_SITE_URL=${{ startsWith(github.ref, 'refs/tags/') && 'https://guitar0.net' || 'https://staging.guitar0.net' }}
cache-from: type=gha
cache-to: type=gha,mode=max
security-scan:
name: Security Scan
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
with:
image-ref: "${{ env.DOCKER_IMAGE }}:${{ needs.build.outputs.version }}"
format: "sarif"
output: "trivy-results.sarif"
severity: "CRITICAL,HIGH"
exit-code: "1"
ignore-unfixed: true
trivyignores: ".trivyignore"
limit-severities-for-sarif: true
- name: Upload Trivy scan results
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: "trivy-results.sarif"
dispatch-staging:
name: Trigger staging deploy
if: github.ref == 'refs/heads/main'
needs: [build, security-scan]
runs-on: ubuntu-latest
steps:
- name: Dispatch deploy to infrastructure repo
uses: peter-evans/repository-dispatch@v4
with:
token: ${{ secrets.INFRA_DISPATCH_TOKEN }}
repository: guitar0-net/infrastructure
event-type: deploy-frontend
client-payload: |
{
"environment": "staging",
"version": "${{ needs.build.outputs.version }}",
"git_sha": "${{ needs.build.outputs.git_sha }}"
}
dispatch-production:
name: Trigger production deploy
if: startsWith(github.ref, 'refs/tags/v')
needs: [build, security-scan]
runs-on: ubuntu-latest
steps:
- name: Dispatch deploy to infrastructure repo
uses: peter-evans/repository-dispatch@v4
with:
token: ${{ secrets.INFRA_DISPATCH_TOKEN }}
repository: guitar0-net/infrastructure
event-type: deploy-frontend
client-payload: |
{
"environment": "production",
"version": "${{ needs.build.outputs.version }}",
"git_sha": "${{ needs.build.outputs.git_sha }}"
}