Skip to content

Commit 7f96b2a

Browse files
authored
updated the dockerfile, docker compose and cd files to reflect the docker changes
1 parent 3426b34 commit 7f96b2a

14 files changed

+360
-70
lines changed

.github/workflows/cd.dev.yml

+25-20
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,40 @@
1-
name: Dev Branch Deployment
2-
1+
name: Dev cd pipeline
32
on:
4-
workflow_run:
5-
workflows: ["CI"]
6-
types:
7-
- completed
8-
branches: [dev]
3+
push:
4+
branches: [devops]
95

106
jobs:
11-
on-success:
7+
build-and-deploy:
128
runs-on: ubuntu-latest
13-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
149
steps:
1510
- name: Checkout code
1611
uses: actions/checkout@v3
1712

18-
- name: Use SSH Action
13+
- name: Build image
14+
run: docker build -t anchor-python-bp-dev:latest -f Dockerfile .
15+
16+
- name: Save image
17+
run: docker save anchor-python-bp-dev:latest | gzip > dev.tar.gz
18+
19+
- name: Copy image to server
20+
uses: appleboy/[email protected]
21+
with:
22+
host: ${{ secrets.HOST }}
23+
username: ${{ secrets.USERNAME }}
24+
password: ${{ secrets.PASSWORD }}
25+
source: "dev.tar.gz"
26+
target: "/home/${{ secrets.USERNAME }}/boilerplate-python/dev_source_code"
27+
28+
- name: Deploy image on server
1929
uses: appleboy/[email protected]
2030
with:
2131
host: ${{ secrets.HOST }}
2232
username: ${{ secrets.USERNAME }}
2333
password: ${{ secrets.PASSWORD }}
2434
script: |
25-
cd python/dev_source_code/
26-
git pull origin dev
27-
source .venv/bin/activate
28-
pip install -r requirements.txt
29-
alembic upgrade head
35+
cd /home/${{ secrets.USERNAME }}/boilerplate-python/dev_source_code
36+
git pull origin devops
37+
docker load --input dev.tar.gz
38+
docker compose -f docker-compose.yml up -d
39+
rm -f dev.tar.gz
3040
31-
on-failure:
32-
runs-on: ubuntu-latest
33-
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
34-
steps:
35-
- run: echo 'The triggering workflow failed'

.github/workflows/cd.dev.yml.bac

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Dev Branch Deployment
2+
3+
on:
4+
workflow_run:
5+
workflows: ["CI"]
6+
types:
7+
- completed
8+
branches: [dev]
9+
10+
jobs:
11+
on-success:
12+
runs-on: ubuntu-latest
13+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v3
17+
18+
- name: Use SSH Action
19+
uses: appleboy/[email protected]
20+
with:
21+
host: ${{ secrets.HOST }}
22+
username: ${{ secrets.USERNAME }}
23+
password: ${{ secrets.PASSWORD }}
24+
script: |
25+
cd python/dev_source_code/
26+
git pull origin dev
27+
source .venv/bin/activate
28+
pip install -r requirements.txt
29+
alembic upgrade head
30+
31+
on-failure:
32+
runs-on: ubuntu-latest
33+
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
34+
steps:
35+
- run: echo 'The triggering workflow failed'

.github/workflows/cd.prod.yml

+24-20
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,39 @@
1-
name: Prod Branch Deployment
2-
1+
name: Prod cd pipeline
32
on:
4-
workflow_run:
5-
workflows: ["CI"]
6-
types:
7-
- completed
8-
branches: [main]
3+
push:
4+
branches: [dev]
95

106
jobs:
11-
on-success:
7+
build-and-deploy:
128
runs-on: ubuntu-latest
13-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
149
steps:
1510
- name: Checkout code
1611
uses: actions/checkout@v3
1712

18-
- name: Use SSH Action
13+
- name: Build image
14+
run: docker build -t anchor-python-bp-prod:latest -f docker/prod/Dockerfile .
15+
16+
- name: Save image
17+
run: docker save anchor-python-bp-prod:latest | gzip > prod.tar.gz
18+
19+
- name: Copy image to server
20+
uses: appleboy/[email protected]
21+
with:
22+
host: ${{ secrets.HOST }}
23+
username: ${{ secrets.USERNAME }}
24+
password: ${{ secrets.PASSWORD }}
25+
source: "prod.tar.gz"
26+
target: "/home/${{ secrets.USERNAME }}/boilerplate-python/prod_source_code/docker/prod"
27+
28+
- name: Deploy image on server
1929
uses: appleboy/[email protected]
2030
with:
2131
host: ${{ secrets.HOST }}
2232
username: ${{ secrets.USERNAME }}
2333
password: ${{ secrets.PASSWORD }}
2434
script: |
25-
cd python/prod_source_code/
35+
cd /home/${{ secrets.USERNAME }}/boilerplate-python/prod_source_code/docker/prod
2636
git pull origin main
27-
source .venv/bin/activate
28-
pip install -r requirements.txt
29-
alembic upgrade head
30-
31-
on-failure:
32-
runs-on: ubuntu-latest
33-
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
34-
steps:
35-
- run: echo 'The triggering workflow failed'
37+
docker load --input prod.tar.gz
38+
docker compose -f docker-compose.yml up -d
39+
rm -f prod.tar.gz

.github/workflows/cd.prod.yml.bac

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Prod Branch Deployment
2+
3+
on:
4+
workflow_run:
5+
workflows: ["CI"]
6+
types:
7+
- completed
8+
branches: [main]
9+
10+
jobs:
11+
on-success:
12+
runs-on: ubuntu-latest
13+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v3
17+
18+
- name: Use SSH Action
19+
uses: appleboy/[email protected]
20+
with:
21+
host: ${{ secrets.HOST }}
22+
username: ${{ secrets.USERNAME }}
23+
password: ${{ secrets.PASSWORD }}
24+
script: |
25+
cd python/prod_source_code/
26+
git pull origin main
27+
source .venv/bin/activate
28+
pip install -r requirements.txt
29+
alembic upgrade head
30+
31+
on-failure:
32+
runs-on: ubuntu-latest
33+
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
34+
steps:
35+
- run: echo 'The triggering workflow failed'

.github/workflows/cd.staging.yml

+23-19
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,39 @@
1-
name: Staging Branch Deployment
2-
1+
name: Staging cd pipeline
32
on:
4-
workflow_run:
5-
workflows: ["CI"]
6-
types:
7-
- completed
3+
push:
84
branches: [staging]
95

106
jobs:
11-
on-success:
7+
build-and-deploy:
128
runs-on: ubuntu-latest
13-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
149
steps:
1510
- name: Checkout code
1611
uses: actions/checkout@v3
1712

18-
- name: Use SSH Action
13+
- name: Build image
14+
run: docker build -t anchor-python-bp-staging:latest -f docker/staging/Dockerfile .
15+
16+
- name: Save image
17+
run: docker save anchor-python-bp-staging:latest | gzip > staging.tar.gz
18+
19+
- name: Copy image to server
20+
uses: appleboy/[email protected]
21+
with:
22+
host: ${{ secrets.HOST }}
23+
username: ${{ secrets.USERNAME }}
24+
password: ${{ secrets.PASSWORD }}
25+
source: "staging.tar.gz"
26+
target: "/home/${{ secrets.USERNAME }}/boilerplate-python/staging_source_code/docker/staging"
27+
28+
- name: Deploy image on server
1929
uses: appleboy/[email protected]
2030
with:
2131
host: ${{ secrets.HOST }}
2232
username: ${{ secrets.USERNAME }}
2333
password: ${{ secrets.PASSWORD }}
2434
script: |
25-
cd python/staging_source_code/
35+
cd /home/${{ secrets.USERNAME }}/boilerplate-python/staging_source_code/docker/staging
2636
git pull origin staging
27-
source .venv/bin/activate
28-
pip install -r requirements.txt
29-
alembic upgrade head
30-
31-
on-failure:
32-
runs-on: ubuntu-latest
33-
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
34-
steps:
35-
- run: echo 'The triggering workflow failed'
37+
docker load --input staging.tar.gz
38+
docker compose -f docker-compose.yml up -d
39+
rm -f staging.tar.gz

.github/workflows/cd.staging.yml.bac

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Staging Branch Deployment
2+
3+
on:
4+
workflow_run:
5+
workflows: ["CI"]
6+
types:
7+
- completed
8+
branches: [staging]
9+
10+
jobs:
11+
on-success:
12+
runs-on: ubuntu-latest
13+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v3
17+
18+
- name: Use SSH Action
19+
uses: appleboy/[email protected]
20+
with:
21+
host: ${{ secrets.HOST }}
22+
username: ${{ secrets.USERNAME }}
23+
password: ${{ secrets.PASSWORD }}
24+
script: |
25+
cd python/staging_source_code/
26+
git pull origin staging
27+
source .venv/bin/activate
28+
pip install -r requirements.txt
29+
alembic upgrade head
30+
31+
on-failure:
32+
runs-on: ubuntu-latest
33+
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
34+
steps:
35+
- run: echo 'The triggering workflow failed'
File renamed without changes.

.github/workflows/pr-deploy.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jobs:
1212
steps:
1313
- name: Checkout to branch
1414
uses: actions/checkout@v4
15+
- name: Copy .env.sample to .env
16+
run: cp .env.sample .env
1517
- id: deploy
1618
name: Pull Request Deploy
1719
uses: hngprojects/pr-deploy@dev
@@ -22,8 +24,8 @@ jobs:
2224
comment: true
2325
context: '.'
2426
dockerfile: 'Dockerfile'
25-
exposed_port: '8000'
27+
exposed_port: '7001'
2628
github_token: ${{ secrets.GITHUB_TOKEN }}
2729
- name: Print Preview Url
2830
run: |
29-
echo "Preview Url: ${{ steps.deploy.outputs.preview-url }}"
31+
echo "Preview Url: ${{ steps.deploy.outputs.preview-url }}"

.github/workflows/test.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Test
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, reopened, closed]
5+
6+
jobs:
7+
test:
8+
runs-on: ubuntu-latest
9+
10+
services:
11+
postgres:
12+
image: postgres:latest
13+
env:
14+
POSTGRES_USER: "username"
15+
POSTGRES_PASSWORD: "password"
16+
POSTGRES_DB: "test"
17+
ports:
18+
- 5432:5432
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v2
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v4
26+
with:
27+
python-version: "3.12"
28+
29+
- name: Cache dependencies
30+
uses: actions/cache@v3
31+
with:
32+
path: ~/.cache/pip
33+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
34+
restore-keys: |
35+
${{ runner.os }}-pip-
36+
37+
- name: Install dependencies
38+
run: |
39+
pip install -r requirements.txt
40+
41+
- name: Copy env file
42+
run: cp .env.sample .env
43+
44+
- name: Run migrations
45+
run: |
46+
alembic upgrade head
47+
48+
- name: Run tests
49+
run: |
50+
PYTHONPATH=. pytest

Dockerfile

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Use an official Python runtime as the base image
2-
FROM python:3.11.9-alpine
2+
FROM python:3.12-alpine
33

44
# Set environment variables
55
ENV PYTHONDONTWRITEBYTECODE=1
@@ -11,17 +11,15 @@ WORKDIR /app
1111
# Install system dependencies
1212
RUN apk add --no-cache curl
1313

14+
#copy the requirements.txt file and install with pip
15+
COPY ./requirements.txt /app/requirements.txt
16+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
17+
1418
# Copy the rest of the backend files
1519
COPY . /app/
1620

17-
# Copy the .env.sample to .env
18-
COPY .env.sample /app/.env
19-
20-
# Install dependencies
21-
RUN pip install --no-cache-dir --upgrade -r requirements.txt
22-
2321
# Expose the port the app runs on
24-
EXPOSE 8000
22+
EXPOSE 7001
2523

2624
# Command to run the application
27-
CMD ["/bin/sh", "-c", "uvicorn main:app --host 0.0.0.0 --port 8000 --reload"]
25+
CMD ["/bin/sh", "-c", "uvicorn main:app --host 0.0.0.0 --port 7001 --reload"]

0 commit comments

Comments
 (0)