Skip to content

Commit

Permalink
Merge pull request #9 from bescka/add_docker_action
Browse files Browse the repository at this point in the history
Add Docker Action
  • Loading branch information
BraunRudolf authored Jul 27, 2024
2 parents 9d15e4f + 44986b3 commit c21a073
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 10 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Docker

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build-containers:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Build and run the container
env:
FASTAPI_SECRET_KEY: ${{secrets.FASTAPI_SECRET_KEY}}
FASTAPI_HASH_ALGORITHM: ${{secrets.FASTAPI_HASH_ALGORITHM}}
ACCESS_TOKEN_EXPIRE_MINUTES: ${{secrets.ACCESS_TOKEN_EXPIRE_MINUTES}}
USER_DB_URL: ${{secrets.DOCKER_USER_DB_URL}}
FILE_DB_URL: ${{secrets.DOCKER_FILE_DB_URL}}
POSTGRES_USER: ${{secrets.POSTGRES_USER}}
POSTGRES_PASSWORD: ${{secrets.POSTGRES_PASSWORD}}
POSTGRES_DB: ${{secrets.POSTGRES_DB}}
NEXT_PUBLIC_ENVIRONMENT: ${{secrets.NEXT_PUBLIC_ENVIRONMENT}}
NEXT_PUBLIC_API_URL: ${{secrets.NEXT_PUBLIC_API_URL}}
run: |
docker-compose -f docker-compose.prod.yml up -d
sleep 30
- name: Check container status
run: docker ps -a

- name: Get container logs
run: docker-compose -f docker-compose.prod.yml logs

- name: Clean up
run: docker-compose -f docker-compose.prod.yml down
17 changes: 17 additions & 0 deletions backend-app/Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.12-slim

# Update and install dependencies
RUN apt-get update \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY /app/ /app/


EXPOSE 8000

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
29 changes: 19 additions & 10 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,59 @@ services:
frontend:
build:
context: ./frontend-app/
dockerfile: Dockerfile
dockerfile: Dockerfile.prod
environment:
- NEXT_PUBLIC_ENVIRONMENT
- NEXT_PUBLIC_API_URL
networks:
- my_network
ports:
- "3000:3000"
depends_on:
- backend
env_file:
- frontend.env

backend:
build:
context: ./backend-app/
dockerfile: Dockerfile
dockerfile: Dockerfile.prod
environment:
- FASTAPI_SECRET_KEY
- FASTAPI_HASH_ALGORITHM
- ACCESS_TOKEN_EXPIRE_MINUTES
- USER_DB_URL
- FILE_DB_URL
networks:
- my_network
ports:
- "8000:8000"
depends_on:
- userdb
- filedb
env_file:
- backend.env

userdb:
image: postgres:13
environment:
- POSTGRES_USER
- POSTGRES_PASSWORD
- POSTGRES_DB
volumes:
- userdb_data:/var/lib/postgresql/data
ports:
- "5433:5432"
networks:
- my_network
env_file:
- database.env
filedb:
image: postgres:13
environment:
- POSTGRES_USER
- POSTGRES_PASSWORD
- POSTGRES_DB
volumes:
- filedb_data:/var/lib/postgresql/data
ports:
- "5432:5432"
networks:
- my_network
env_file:
- database.env

volumes:
userdb_data:
Expand Down
13 changes: 13 additions & 0 deletions frontend-app/Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:slim

WORKDIR /app

COPY package.json ./

RUN npm install

COPY . .

EXPOSE 3000

CMD ["npm", "run", "dev"]

0 comments on commit c21a073

Please sign in to comment.