Skip to content

Commit f204f51

Browse files
authored
chore(ci): cache & restructure GHAs + Docker, fix race in deploy (#53)
chore: Update CI/CD workflows and Docker configurations * Enhanced `.dockerignore` to exclude additional build artifacts and environment files. * Updated `claude.md` with detailed descriptions of CI/CD workflows, including new deployment strategies. * Refactored GitHub Actions workflows for code quality, deployment, and Terraform management to improve efficiency and clarity. * Removed obsolete Docker build and push workflows, consolidating functionality into the new deployment strategies. * Improved Dockerfile configurations for better caching and installation processes. These changes streamline the CI/CD pipeline and enhance the overall development experience. Co-authored-by: Tushar Shah <twoshark@users.noreply.github.com>
1 parent 731d330 commit f204f51

11 files changed

Lines changed: 173 additions & 158 deletions

.dockerignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,13 @@ terraform
33
.vscode
44
.git
55
.cache
6+
7+
node_modules
8+
**/node_modules
9+
**/build
10+
**/dist
11+
12+
*.log
13+
.env
14+
.env.*
15+
!.env.example

.github/workflows/code-quality.yml

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,55 @@
11
name: Code Quality and Styles
22

33
on:
4+
pull_request:
45
push:
6+
branches: [main]
7+
8+
permissions:
9+
contents: read
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
514

615
jobs:
716
code-quality-and-style:
817
strategy:
18+
fail-fast: false
919
matrix:
1020
project:
11-
- packages/backend
12-
- packages/frontend
21+
- frontend
22+
- backend
1323

1424
runs-on: ubuntu-latest
1525

1626
steps:
1727
- name: Checkout code
18-
uses: actions/checkout@v2
28+
uses: actions/checkout@v4
1929

2030
- name: Install Node.js
21-
uses: actions/setup-node@v2
31+
uses: actions/setup-node@v4
2232
with:
23-
node-version: 21
24-
25-
- name: Install Tools
26-
run: |
27-
echo "Installing tools..."
28-
npm install -g pnpm eslint
33+
node-version: 22
34+
cache: 'yarn'
35+
36+
# pnpm is needed because `lint`/`style` scripts use `pnpx` to pin the
37+
# eslint/prettier version. eslint is intentionally NOT installed
38+
# globally; `pnpx eslint@8.57.0` fetches the pinned version itself.
39+
# Pinned to v9 because (a) `pnpx` was deprecated and removed from
40+
# later versions, and (b) leaving it unpinned silently drifts on
41+
# every CI run.
42+
- name: Install pnpm
43+
run: npm install -g pnpm@9
2944

3045
- name: Install dependencies
31-
run: |
32-
echo "Installing dependencies..."
33-
cd ${{ matrix.project }}
34-
yarn install
46+
run: yarn install --frozen-lockfile
3547

3648
- name: Style Check
37-
run: |
38-
echo "Running style check..."
39-
cd ${{ matrix.project }}
40-
yarn style
49+
run: yarn workspace ${{ matrix.project }} style
4150

4251
- name: Lint
43-
run: |
44-
echo "Running lint..."
45-
cd ${{ matrix.project }}
46-
yarn lint
52+
run: yarn workspace ${{ matrix.project }} lint
4753

4854
- name: Build
49-
run: |
50-
echo "Running build..."
51-
cd ${{ matrix.project }}
52-
yarn build
53-
54-
# - name: Test
55-
# run: |
56-
# cd ${{ matrix.project }}
57-
# yarn test --all
58-
59-
- name: Clean up
60-
run: |
61-
echo "Cleaning up..."
62-
cd ${{ matrix.project }}
63-
rm -f eslint-report.json
55+
run: yarn workspace ${{ matrix.project }} build

.github/workflows/deploy-frontend.yml

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ on:
1414
permissions:
1515
contents: read
1616

17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.ref }}
19+
cancel-in-progress: false
20+
1721
jobs:
1822
deploy-frontend:
1923
name: Deploy Frontend
@@ -31,42 +35,26 @@ jobs:
3135

3236
steps:
3337
- name: Checkout code
34-
uses: actions/checkout@v3
38+
uses: actions/checkout@v4
3539
with:
3640
ref: ${{ github.event.inputs.ref || github.ref }}
3741

3842
- name: Install Node.js
39-
uses: actions/setup-node@v2
43+
uses: actions/setup-node@v4
4044
with:
41-
node-version: 21
42-
43-
- name: Install Tools
44-
run: npm install -g pnpm eslint
45+
node-version: 22
46+
cache: 'yarn'
4547

4648
- name: Install dependencies
47-
run: |
48-
cd packages/frontend
49-
yarn install
50-
51-
- name: Style Check
52-
run: |
53-
cd packages/frontend
54-
yarn style
55-
56-
- name: Lint
57-
run: |
58-
cd packages/frontend
59-
yarn lint
49+
run: yarn install --frozen-lockfile
6050

6151
- name: Build
62-
run: |
63-
cd packages/frontend
64-
yarn build
52+
run: yarn workspace frontend build
6553
env:
6654
NODE_ENV: production
6755

6856
- name: Configure AWS credentials
69-
uses: aws-actions/configure-aws-credentials@v2
57+
uses: aws-actions/configure-aws-credentials@v4
7058
with:
7159
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
7260
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'Infrastructure Deployment'
1+
name: Deploy
22

33
on:
44
push:
@@ -7,22 +7,84 @@ on:
77
permissions:
88
contents: read
99

10+
# Don't cancel mid-deploy: cancelling Terraform apply would leave state
11+
# inconsistent. Queue follow-up runs instead.
12+
concurrency:
13+
group: deploy-${{ github.ref }}
14+
cancel-in-progress: false
15+
1016
jobs:
17+
build-app:
18+
name: Build & Push App Image
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v3
26+
27+
- name: Log in to Docker Hub
28+
uses: docker/login-action@v3
29+
with:
30+
username: ${{ secrets.DOCKER_USERNAME }}
31+
password: ${{ secrets.DOCKER_PASSWORD }}
32+
33+
- name: Build and push primary Docker image
34+
uses: docker/build-push-action@v5
35+
with:
36+
context: .
37+
file: ./docker/Dockerfile
38+
push: true
39+
tags: rnavt/people-manager:latest,rnavt/people-manager:${{ github.sha }}
40+
cache-from: type=gha,scope=app
41+
cache-to: type=gha,scope=app,mode=max
42+
43+
build-migration:
44+
name: Build & Push Migration Image
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: Checkout
48+
uses: actions/checkout@v4
49+
50+
- name: Set up Docker Buildx
51+
uses: docker/setup-buildx-action@v3
52+
53+
- name: Log in to Docker Hub
54+
uses: docker/login-action@v3
55+
with:
56+
username: ${{ secrets.DOCKER_USERNAME }}
57+
password: ${{ secrets.DOCKER_PASSWORD }}
58+
59+
- name: Build and push migration Docker image
60+
uses: docker/build-push-action@v5
61+
with:
62+
context: .
63+
file: ./docker/Dockerfile.migration
64+
push: true
65+
tags: rnavt/people-manager:latest-migration,rnavt/people-manager:${{ github.sha }}-migration
66+
cache-from: type=gha,scope=migration
67+
cache-to: type=gha,scope=migration,mode=max
68+
1169
terraform:
12-
name: 'Terraform'
70+
name: Terraform Apply & Migrate
71+
# Wait for both images so Terraform never references a tag that hasn't
72+
# been pushed yet.
73+
needs: [build-app, build-migration]
1374
runs-on: ubuntu-latest
1475
environment: production
15-
1676
defaults:
1777
run:
1878
shell: bash
79+
env:
80+
TF_PLUGIN_CACHE_DIR: ${{ github.workspace }}/.terraform.d/plugin-cache
1981

2082
steps:
2183
- name: Checkout
22-
uses: actions/checkout@v3
84+
uses: actions/checkout@v4
2385

2486
- name: Configure AWS credentials
25-
uses: aws-actions/configure-aws-credentials@v2
87+
uses: aws-actions/configure-aws-credentials@v4
2688
with:
2789
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
2890
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
@@ -31,13 +93,23 @@ jobs:
3193
- name: Setup Terraform
3294
uses: hashicorp/setup-terraform@v3
3395

96+
- name: Cache Terraform plugins
97+
uses: actions/cache@v4
98+
with:
99+
path: ${{ env.TF_PLUGIN_CACHE_DIR }}
100+
key: ${{ runner.os }}-terraform-${{ hashFiles('terraform/.terraform.lock.hcl', 'terraform/**/*.tf') }}
101+
restore-keys: ${{ runner.os }}-terraform-
102+
103+
- name: Create plugin cache dir
104+
run: mkdir -p "$TF_PLUGIN_CACHE_DIR"
105+
34106
- name: Terraform Init
35107
working-directory: terraform/
36108
run: terraform init -backend-config "bucket=terraform-state-nilo2024" -backend-config "key=people-manager.tfstate"
37109

38110
- name: Terraform Format
39111
working-directory: terraform/
40-
run: terraform fmt
112+
run: terraform fmt -check -recursive
41113

42114
- name: Terraform Plan
43115
working-directory: terraform/

.github/workflows/destroy.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
permissions:
77
contents: read
88

9+
concurrency:
10+
group: destroy-${{ github.ref }}
11+
cancel-in-progress: false
12+
913
jobs:
1014
terraform:
1115
name: 'Terraform'
@@ -18,10 +22,10 @@ jobs:
1822

1923
steps:
2024
- name: Checkout
21-
uses: actions/checkout@v3
25+
uses: actions/checkout@v4
2226

2327
- name: Configure AWS credentials
24-
uses: aws-actions/configure-aws-credentials@v2
28+
uses: aws-actions/configure-aws-credentials@v4
2529
with:
2630
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
2731
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
@@ -31,7 +35,7 @@ jobs:
3135
uses: hashicorp/setup-terraform@v3
3236

3337
- name: Terraform Init
34-
working-directory: terraform/`
38+
working-directory: terraform/
3539
run: terraform init -backend-config "bucket=terraform-state-nilo2024" -backend-config "key=people-manager.tfstate"
3640

3741
- name: Terraform Plan Check

.github/workflows/docker-build-push-migration.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

.github/workflows/docker-build-push.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)