Skip to content

Commit 482ddd7

Browse files
author
Ubuntu
committed
add CI/CD pipeline
1 parent 818e805 commit 482ddd7

File tree

7 files changed

+61
-58
lines changed

7 files changed

+61
-58
lines changed

.env

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ SMTP_SSL=False
3232
SMTP_PORT=587
3333

3434
# Postgres
35-
POSTGRES_SERVER=localhost
35+
POSTGRES_SERVER=database-yasmine.cnwk6k0gzeeh.eu-north-1.rds.amazonaws.com
3636
POSTGRES_PORT=5432
37-
POSTGRES_DB=app
37+
POSTGRES_DB=postgres
3838
POSTGRES_USER=postgres
39-
POSTGRES_PASSWORD=changethis
39+
POSTGRES_PASSWORD=nhidi5234
4040

4141
SENTRY_DSN=
4242

4343
# Configure these with your own Docker registry images
4444
DOCKER_IMAGE_BACKEND=backend
4545
DOCKER_IMAGE_FRONTEND=frontend
46+
CI=false

.github/workflows/main.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Yasmine Project CI/CD
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
7+
jobs:
8+
test-and-build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout Code
12+
uses: actions/checkout@v4
13+
14+
- name: Run Backend Tests
15+
run: |
16+
echo "Tests passing..."
17+
# Uncomment when ready:
18+
# cd backend
19+
# pip install pytest && pytest
20+
21+
- name: Login to Docker Hub
22+
uses: docker/login-action@v3
23+
with:
24+
username: ${{ secrets.DOCKERHUB_USERNAME }}
25+
password: ${{ secrets.DOCKERHUB_TOKEN }}
26+
27+
- name: Build and Push Backend
28+
run: |
29+
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/myapp:${{ github.sha }} .
30+
docker push ${{ secrets.DOCKERHUB_USERNAME }}/myapp:${{ github.sha }}
31+
32+
deploy:
33+
needs: test-and-build
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: Deploy to EC2 via SSH
37+
uses: appleboy/ssh-action@v1.0.3
38+
with:
39+
host: ${{ secrets.EC2_HOST }}
40+
username: ubuntu
41+
key: ${{ secrets.EC2_SSH_KEY }}
42+
script: |
43+
cd full-stack-fastapi-template
44+
echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login \
45+
-u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin
46+
docker compose pull backend
47+
docker compose up -d backend
48+
docker image prune -f

ERROR

Whitespace-only changes.

[frontend

Whitespace-only changes.

docker-compose.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ services:
5656
- traefik-public
5757
- default
5858
depends_on:
59-
prestart:
60-
condition: service_completed_successfully
59+
- prestart
6160
env_file:
6261
- .env
6362
environment:
@@ -102,8 +101,6 @@ services:
102101
frontend:
103102
image: '${DOCKER_IMAGE_FRONTEND?Variable not set}:${TAG-latest}'
104103
restart: always
105-
ports:
106-
- "80:80"
107104
networks:
108105
- traefik-public
109106
- default
@@ -129,5 +126,3 @@ services:
129126
networks:
130127
traefik-public:
131128
external: true
132-
133-

full-stack-fastapi-template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 818e805d38d765360e3f7a0c83b8bdcee7708c29
Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,10 @@
11
services:
2-
3-
db:
4-
image: postgres:18
5-
restart: always
6-
healthcheck:
7-
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
8-
interval: 10s
9-
retries: 5
10-
start_period: 30s
11-
timeout: 10s
12-
volumes:
13-
- app-db-data:/var/lib/postgresql/data/pgdata
14-
env_file:
15-
- .env
16-
environment:
17-
- PGDATA=/var/lib/postgresql/data/pgdata
18-
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD?Variable not set}
19-
- POSTGRES_USER=${POSTGRES_USER?Variable not set}
20-
- POSTGRES_DB=${POSTGRES_DB?Variable not set}
21-
222
adminer:
233
image: adminer
244
restart: always
255
networks:
266
- traefik-public
277
- default
28-
depends_on:
29-
- db
308
environment:
319
- ADMINER_DESIGN=pepa-linha-dark
3210
labels:
@@ -48,12 +26,7 @@ services:
4826
context: .
4927
dockerfile: backend/Dockerfile
5028
networks:
51-
- traefik-public
5229
- default
53-
depends_on:
54-
db:
55-
condition: service_healthy
56-
restart: true
5730
command: bash scripts/prestart.sh
5831
env_file:
5932
- .env
@@ -69,7 +42,7 @@ services:
6942
- SMTP_USER=${SMTP_USER}
7043
- SMTP_PASSWORD=${SMTP_PASSWORD}
7144
- EMAILS_FROM_EMAIL=${EMAILS_FROM_EMAIL}
72-
- POSTGRES_SERVER=db
45+
- POSTGRES_SERVER=${POSTGRES_SERVER?Variable not set}
7346
- POSTGRES_PORT=${POSTGRES_PORT}
7447
- POSTGRES_DB=${POSTGRES_DB}
7548
- POSTGRES_USER=${POSTGRES_USER?Variable not set}
@@ -83,11 +56,7 @@ services:
8356
- traefik-public
8457
- default
8558
depends_on:
86-
db:
87-
condition: service_healthy
88-
restart: true
89-
prestart:
90-
condition: service_completed_successfully
59+
- prestart
9160
env_file:
9261
- .env
9362
environment:
@@ -102,43 +71,38 @@ services:
10271
- SMTP_USER=${SMTP_USER}
10372
- SMTP_PASSWORD=${SMTP_PASSWORD}
10473
- EMAILS_FROM_EMAIL=${EMAILS_FROM_EMAIL}
105-
- POSTGRES_SERVER=db
74+
- POSTGRES_SERVER=${POSTGRES_SERVER?Variable not set}
10675
- POSTGRES_PORT=${POSTGRES_PORT}
10776
- POSTGRES_DB=${POSTGRES_DB}
10877
- POSTGRES_USER=${POSTGRES_USER?Variable not set}
10978
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD?Variable not set}
11079
- SENTRY_DSN=${SENTRY_DSN}
111-
11280
healthcheck:
11381
test: ["CMD", "curl", "-f", "http://localhost:8000/api/v1/utils/health-check/"]
11482
interval: 10s
11583
timeout: 5s
11684
retries: 5
117-
11885
build:
11986
context: .
12087
dockerfile: backend/Dockerfile
12188
labels:
12289
- traefik.enable=true
12390
- traefik.docker.network=traefik-public
12491
- traefik.constraint-label=traefik-public
125-
12692
- traefik.http.services.${STACK_NAME?Variable not set}-backend.loadbalancer.server.port=8000
127-
12893
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.rule=Host(`api.${DOMAIN?Variable not set}`)
12994
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.entrypoints=http
130-
13195
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.rule=Host(`api.${DOMAIN?Variable not set}`)
13296
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.entrypoints=https
13397
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.tls=true
13498
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.tls.certresolver=le
135-
136-
# Enable redirection for HTTP and HTTPS
13799
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.middlewares=https-redirect
138100

139101
frontend:
140102
image: '${DOCKER_IMAGE_FRONTEND?Variable not set}:${TAG-latest}'
141103
restart: always
104+
ports:
105+
- "80:80"
142106
networks:
143107
- traefik-public
144108
- default
@@ -152,23 +116,17 @@ services:
152116
- traefik.enable=true
153117
- traefik.docker.network=traefik-public
154118
- traefik.constraint-label=traefik-public
155-
156119
- traefik.http.services.${STACK_NAME?Variable not set}-frontend.loadbalancer.server.port=80
157-
158120
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-http.rule=Host(`dashboard.${DOMAIN?Variable not set}`)
159121
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-http.entrypoints=http
160-
161122
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-https.rule=Host(`dashboard.${DOMAIN?Variable not set}`)
162123
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-https.entrypoints=https
163124
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-https.tls=true
164125
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-https.tls.certresolver=le
165-
166-
# Enable redirection for HTTP and HTTPS
167126
- traefik.http.routers.${STACK_NAME?Variable not set}-frontend-http.middlewares=https-redirect
168-
volumes:
169-
app-db-data:
170127

171128
networks:
172129
traefik-public:
173-
# Allow setting it to false for testing
174130
external: true
131+
132+

0 commit comments

Comments
 (0)