Skip to content

Commit 1c3e6a9

Browse files
authored
chore: bump spring version to 4.0.5 (#27)
* chore: bump spring version to 4.0.5 * feat: add docker build to CI workflow * feat: add staging deploy - wip * fix: change triggers to include PR changes * feat: add server ci and deploy to stg * chore: add app build candidate * remove from branch, get from main * fix: build app candidate * fix: build app candidate * fix: fe changes in the app * fix: app ci workflow dispatch * chore: improve PR ci and cd * feat: make deployments always happen for PRs * feat: improve workflow names
1 parent 3bb21e5 commit 1c3e6a9

13 files changed

Lines changed: 1023 additions & 250 deletions

File tree

.github/workflows/build-app-candidate.yml

Lines changed: 11 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -34,63 +34,24 @@ jobs:
3434
with:
3535
images: ghcr.io/${{ github.repository }}/app
3636
tags: |
37-
type=raw,value=candidade
37+
type=raw,value=candidate
3838
39-
- name: Build and push Docker image
40-
uses: docker/build-push-action@v5
41-
with:
42-
context: ./client
43-
push: true
44-
tags: candidate
45-
cache-from: type=gha
46-
cache-to: type=gha,mode=max
47-
build-args: |
48-
VITE_BUILD=v${DATE}.${{ github.run_number }}"
49-
name: Build App Candidate
50-
51-
on:
52-
workflow_dispatch:
53-
54-
jobs:
55-
build-and-push-app:
56-
name: Build & Push App
57-
runs-on: ubuntu-latest
58-
permissions:
59-
contents: read
60-
packages: write
61-
62-
steps:
63-
- name: Checkout code
64-
uses: actions/checkout@v4
65-
with:
66-
fetch-depth: 0
67-
ref: ${{ github.ref }}
68-
69-
- name: Set up Docker Buildx
70-
uses: docker/setup-buildx-action@v3
71-
72-
- name: Log in to GitHub Container Registry
73-
uses: docker/login-action@v3
74-
with:
75-
registry: ghcr.io
76-
username: ${{ github.actor }}
77-
password: ${{ secrets.GITHUB_TOKEN }}
78-
79-
- name: Extract metadata for Docker
80-
id: meta
81-
uses: docker/metadata-action@v5
82-
with:
83-
images: ghcr.io/${{ github.repository }}/app
84-
tags: |
85-
type=raw,value=candidade
39+
- name: Generate version tag
40+
id: version
41+
run: |
42+
DATE=$(date +'%Y.%m.%d')
43+
TAG="app-v${DATE}.${{ github.run_number }}"
44+
echo "tag=${TAG}" >> $GITHUB_OUTPUT
45+
echo "Generated tag: ${TAG}"
8646
8747
- name: Build and push Docker image
8848
uses: docker/build-push-action@v5
8949
with:
9050
context: ./client
9151
push: true
92-
tags: candidate
52+
tags: ${{ steps.meta.outputs.tags }}
53+
labels: ${{ steps.meta.outputs.labels }}
9354
cache-from: type=gha
9455
cache-to: type=gha,mode=max
9556
build-args: |
96-
VITE_BUILD=v${DATE}.${{ github.run_number }}"
57+
VITE_BUILD=${{ steps.version.outputs.tag }}

.github/workflows/client-ci.yml

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
name: Frontend CI
1+
name: Frontend PR
22

33
on:
44
workflow_dispatch:
5-
push:
5+
pull_request:
6+
types: [opened, synchronize, reopened]
67
branches:
7-
- '**'
8+
- 'main'
89
paths:
910
- 'client/**/*.html'
1011
- 'client/**/*.png'
@@ -18,8 +19,8 @@ on:
1819
- '.github/workflows/client-ci.yml'
1920

2021
jobs:
21-
build-and-push:
22-
name: Frontend CI
22+
run-checks:
23+
name: Checks
2324
runs-on: ubuntu-latest
2425
permissions:
2526
contents: read
@@ -51,3 +52,55 @@ jobs:
5152
- name: Run tests
5253
run: npm run test:no-watch
5354
working-directory: ./client
55+
56+
build-and-push:
57+
name: Build & Push
58+
runs-on: ubuntu-latest
59+
needs: ["run-checks"]
60+
permissions:
61+
contents: write
62+
packages: write
63+
64+
steps:
65+
- name: Checkout code
66+
uses: actions/checkout@v4
67+
with:
68+
fetch-depth: 0
69+
70+
- name: Set up Docker Buildx
71+
uses: docker/setup-buildx-action@v3
72+
73+
- name: Log in to GitHub Container Registry
74+
uses: docker/login-action@v3
75+
with:
76+
registry: ghcr.io
77+
username: ${{ github.actor }}
78+
password: ${{ secrets.GITHUB_TOKEN }}
79+
80+
- name: Extract metadata for Docker
81+
id: meta
82+
uses: docker/metadata-action@v5
83+
with:
84+
images: ghcr.io/${{ github.repository }}/app
85+
tags: |
86+
type=raw,value=candidate
87+
88+
- name: Generate version tag
89+
id: version
90+
run: |
91+
DATE=$(date +'%Y.%m.%d')
92+
TAG="app-v${DATE}.${{ github.run_number }}"
93+
echo "tag=${TAG}" >> $GITHUB_OUTPUT
94+
echo "Generated tag: ${TAG}"
95+
96+
- name: Build and push Docker image
97+
uses: docker/build-push-action@v5
98+
with:
99+
context: ./client
100+
push: true
101+
tags: ${{ steps.meta.outputs.tags }}
102+
labels: ${{ steps.meta.outputs.labels }}
103+
cache-from: type=gha
104+
cache-to: type=gha,mode=max
105+
build-args: |
106+
VITE_BUILD=${{ steps.version.outputs.tag }}

.github/workflows/deploy-stg.yml

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
name: Deploy to staging
2+
3+
on:
4+
workflow_dispatch:
5+
workflow_run:
6+
workflows: [ "Backend PR", "Frontend PR" ]
7+
types: [ completed ]
8+
9+
jobs:
10+
terraform-plan-stg:
11+
name: Plan changs to staging
12+
runs-on: ubuntu-latest
13+
outputs:
14+
no_changes: ${{ steps.check-changes.outputs.no_changes }}
15+
permissions:
16+
contents: read
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Setup Terraform
24+
uses: hashicorp/setup-terraform@v3
25+
26+
- name: Setup kubectl
27+
uses: azure/setup-kubectl@v4
28+
29+
- name: Setup Kubeconfig
30+
run: |
31+
mkdir -p ~/.kube
32+
echo "${{ secrets.KUBECONFIG_DATA }}" | base64 -d > ~/.kube/config
33+
chmod 600 ~/.kube/config
34+
35+
- name: Validate cluster access
36+
run: |
37+
kubectl cluster-info
38+
kubectl get namespace tasknote-stg
39+
40+
- name: Determine deployment values
41+
id: deploy-vars
42+
run: |
43+
backend_image="ghcr.io/rmcampos/tasknote/api:candidate"
44+
frontend_image="ghcr.io/rmcampos/tasknote/app:candidate"
45+
46+
echo "backend_image=$backend_image" >> "$GITHUB_OUTPUT"
47+
echo "frontend_image=$frontend_image" >> "$GITHUB_OUTPUT"
48+
49+
- name: Terraform Fmt -check -diff
50+
working-directory: terraform-stg
51+
run: terraform fmt -check -diff
52+
53+
- name: Terraform Init
54+
working-directory: terraform-stg
55+
env:
56+
AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
57+
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
58+
run: terraform init -input=false
59+
60+
- name: Terraform Validate
61+
working-directory: terraform-stg
62+
run: terraform validate
63+
64+
- name: Terraform Plan
65+
id: check-changes
66+
working-directory: terraform-stg
67+
env:
68+
AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
69+
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
70+
run: |
71+
timeout 1m terraform plan -input=false -out=tfplan \
72+
-var="db_user=${{ secrets.DB_USER }}" \
73+
-var="db_password=${{ secrets.DB_PASSWORD }}" \
74+
-var="db_name=${{ secrets.DB_NAME }}" \
75+
-var="security_key=${{ secrets.JWT_SECURITY_KEY }}" \
76+
-var="mailgun_apikey=${{ secrets.MAILGUN_API_KEY }}" \
77+
-var="backend_image=${{ steps.deploy-vars.outputs.backend_image }}" \
78+
-var="frontend_image=${{ steps.deploy-vars.outputs.frontend_image }}"
79+
terraform show -json tfplan > tfplan.json
80+
if jq -e '.resource_changes | length == 0' tfplan.json >/dev/null; then
81+
echo "no_changes=true" >> "$GITHUB_OUTPUT"
82+
echo "No changes to apply."
83+
exit 0
84+
else
85+
echo "Changes detected. Proceeding with apply"
86+
echo "no_changes=false" >> "$GITHUB_OUTPUT"
87+
fi
88+
89+
- name: Upload plan artifact
90+
uses: actions/upload-artifact@v4
91+
with:
92+
name: tfplan
93+
path: terraform/tfplan
94+
95+
terraform-apply:
96+
runs-on: ubuntu-latest
97+
needs: terraform-plan-stg
98+
if: >
99+
(github.event_name == 'push' || github.event_name == 'workflow_run')
100+
&& needs.terraform-plan-stg.outputs.no_changes == 'false'
101+
environment:
102+
name: staging
103+
permissions:
104+
contents: read
105+
steps:
106+
- name: Checkout code
107+
uses: actions/checkout@v6
108+
109+
- name: Setup Terraform
110+
uses: hashicorp/setup-terraform@v3
111+
112+
- name: Download plan artifact
113+
uses: actions/download-artifact@v4
114+
with:
115+
name: tfplan
116+
path: terraform
117+
118+
- name: Setup Kubeconfig
119+
run: |
120+
mkdir -p ~/.kube
121+
echo "${{ secrets.KUBECONFIG_DATA }}" | base64 -d > ~/.kube/config
122+
chmod 600 ~/.kube/config
123+
124+
- name: Terraform Init
125+
working-directory: terraform-stg
126+
env:
127+
AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
128+
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
129+
run: terraform init -input=false
130+
131+
- name: Terraform Apply
132+
working-directory: terraform-stg
133+
env:
134+
AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
135+
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
136+
run: timeout 1m terraform apply tfplan

.github/workflows/deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy to K3s
1+
name: Deploy to prod
22

33
on:
44
workflow_dispatch:
@@ -14,7 +14,7 @@ on:
1414
required: false
1515
default: "true"
1616
workflow_run:
17-
workflows: [ "Backend Build & Push", "Frontend Build & Push" ]
17+
workflows: [ "Backend Main", "Frontend Main" ]
1818
types: [ completed ]
1919

2020
jobs:

.github/workflows/main-client.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Frontend Build & Push
1+
name: Frontend Main
22

33
on:
44
workflow_dispatch:
@@ -19,7 +19,7 @@ on:
1919

2020
jobs:
2121
build-and-push:
22-
name: Frontend Build & Push
22+
name: Build & Push
2323
runs-on: ubuntu-latest
2424
permissions:
2525
contents: write

.github/workflows/main-server.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Backend Build & Push
1+
name: Backend Main
22

33
on:
44
workflow_dispatch:
@@ -13,7 +13,7 @@ on:
1313

1414
jobs:
1515
build-and-push:
16-
name: Backend Build & Push
16+
name: Build & Push
1717
runs-on: ubuntu-latest
1818
permissions:
1919
contents: write

0 commit comments

Comments
 (0)