Skip to content

Commit d7d5448

Browse files
[feat] update github main workflow to text deployment to aws ecr
1 parent ec04d30 commit d7d5448

2 files changed

Lines changed: 136 additions & 23 deletions

File tree

.dockerignore

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Ignore dependencies and build output
2+
node_modules/
3+
dist/
4+
out/
5+
.tmp/
6+
.cache/
7+
8+
# Ignore Vite, Webpack, and React-specific build artifacts
9+
.vite/
10+
.vitepress/
11+
.eslintcache
12+
.npm/
13+
coverage/
14+
jest/
15+
cypress/
16+
cypress/screenshots/
17+
cypress/videos/
18+
reports/
19+
20+
# Ignore environment and config files (sensitive data)
21+
*.env*
22+
*.log
23+
24+
# Ignore TypeScript build artifacts (if using TypeScript)
25+
*.tsbuildinfo
26+
27+
# Ignore lockfiles (optional if using Docker for package installation)
28+
npm-debug.log*
29+
yarn-debug.log*
30+
yarn-error.log*
31+
pnpm-debug.log*
32+
33+
# Ignore local development files
34+
.git/
35+
.gitignore
36+
.vscode/
37+
.idea/
38+
*.swp
39+
.DS_Store
40+
Thumbs.db
41+
42+
# Ignore Docker-related files (to avoid copying unnecessary configs)
43+
Dockerfile
44+
.dockerignore
45+
docker-compose.yml
46+
docker-compose.override.yml
47+
48+
# Ignore build-specific cache files
49+
*.lock
50+
51+
# Ignore AI generated files
52+
.ai/
53+
.ai-temp/
54+
.cursor/
55+
.claude/
56+
.kiro/
57+
.vscode-ai/

.github/workflows/main.yml

Lines changed: 79 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,43 +67,99 @@ jobs:
6767
retention-days: 7
6868

6969
# Step 3: Build and Deploy (only on main branch)
70+
# build-and-deploy:
71+
# name: Build & Deploy to Docker Hub
72+
# runs-on: ubuntu-latest
73+
# needs: [lint, test]
74+
75+
# steps:
76+
# - name: Checkout code
77+
# uses: actions/checkout@v4
78+
79+
# - name: Set up QEMU
80+
# uses: docker/setup-qemu-action@v3
81+
82+
# - name: Set up Docker Buildx
83+
# uses: docker/setup-buildx-action@v3
84+
85+
# - name: Extract metadata
86+
# id: meta
87+
# run: |
88+
# echo "short_sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
89+
# echo "date=$(date +'%Y%m%d')" >> "$GITHUB_OUTPUT"
90+
91+
# - name: Log in to Docker Hub
92+
# uses: docker/login-action@v3
93+
# with:
94+
# username: ${{ secrets.DOCKER_USERNAME }}
95+
# password: ${{ secrets.DOCKERHUB_TOKEN }}
96+
97+
# - name: Build and push production image
98+
# uses: docker/build-push-action@v6
99+
# with:
100+
# context: .
101+
# file: Dockerfile
102+
# push: true
103+
# platforms: linux/amd64,linux/arm64
104+
# tags: |
105+
# ${{ env.DOCKERHUB_REPO }}:latest
106+
# ${{ env.DOCKERHUB_REPO }}:${{ steps.meta.outputs.short_sha }}
107+
# ${{ env.DOCKERHUB_REPO }}:${{ steps.meta.outputs.date }}
108+
# cache-from: type=gha
109+
# cache-to: type=gha,mode=max
110+
111+
# Step 4: Build and Deploy to AWS
112+
# Step 2: Build and (conditionally) Deploy
70113
build-and-deploy:
71-
name: Build & Deploy to Docker Hub
114+
name: Build & Deploy to AWS ECS Fargate
72115
runs-on: ubuntu-latest
73116
needs: [lint, test]
74117

118+
# Only run on develop branch (For test purposes). To be replaced with main branch when ready.
119+
if: github.event_name == 'push' && github.ref == 'refs/heads/develop'
120+
75121
steps:
76122
- name: Checkout code
77123
uses: actions/checkout@v4
78124

79-
- name: Set up QEMU
80-
uses: docker/setup-qemu-action@v3
125+
- name: Configure AWS credentials
126+
uses: aws-actions/configure-aws-credentials@v4
127+
with:
128+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
129+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
130+
aws-region: ${{ secrets.AWS_REGION }}
81131

82-
- name: Set up Docker Buildx
83-
uses: docker/setup-buildx-action@v3
132+
- name: Login to Amazon ECR
133+
uses: aws-actions/amazon-ecr-login@v2
84134

85135
- name: Extract metadata
86136
id: meta
87137
run: |
88138
echo "short_sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
89139
echo "date=$(date +'%Y%m%d')" >> "$GITHUB_OUTPUT"
90140
91-
- name: Log in to Docker Hub
92-
uses: docker/login-action@v3
93-
with:
94-
username: ${{ secrets.DOCKER_USERNAME }}
95-
password: ${{ secrets.DOCKERHUB_TOKEN }}
141+
- name: Build Docker image
142+
id: build-image
143+
run: |
144+
IMAGE_TAG=${{ steps.meta.outputs.short_sha }}
145+
ECR_IMAGE=${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ env.ECR_REPOSITORY }}:$IMAGE_TAG
146+
docker build -t $ECR_IMAGE .
147+
echo "ECR_IMAGE=$ECR_IMAGE" >> $GITHUB_ENV
148+
149+
# Only push image & deploy when pushing to main
150+
- name: Push image to ECR
151+
# Only run on develop branch (For test purposes). To be replaced with main branch when ready.
152+
if: github.event_name == 'push' && github.ref == 'refs/heads/develop'
153+
run: |
154+
docker push $ECR_IMAGE
96155
97-
- name: Build and push production image
98-
uses: docker/build-push-action@v6
99-
with:
100-
context: .
101-
file: Dockerfile
102-
push: true
103-
platforms: linux/amd64,linux/arm64
104-
tags: |
105-
${{ env.DOCKERHUB_REPO }}:latest
106-
${{ env.DOCKERHUB_REPO }}:${{ steps.meta.outputs.short_sha }}
107-
${{ env.DOCKERHUB_REPO }}:${{ steps.meta.outputs.date }}
108-
cache-from: type=gha
109-
cache-to: type=gha,mode=max
156+
- name: Force new ECS deployment
157+
# Only run on develop branch (For test purposes). To be replaced with main branch when ready.
158+
if: github.event_name == 'push' && github.ref == 'refs/heads/develop'
159+
run: |
160+
echo "Triggering ECS service update..."
161+
aws ecs update-service \
162+
--cluster ${{ env.ECS_CLUSTER }} \
163+
--service ${{ env.ECS_SERVICE }} \
164+
--force-new-deployment \
165+
--region ${{ secrets.AWS_REGION }}

0 commit comments

Comments
 (0)