Skip to content

Commit

Permalink
added postgresql container
Browse files Browse the repository at this point in the history
  • Loading branch information
SilasPeters committed May 16, 2024
1 parent 27cbd1b commit e99d813
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 40 deletions.
14 changes: 0 additions & 14 deletions .devcontainer/Dockerfile

This file was deleted.

26 changes: 26 additions & 0 deletions .devcontainer/Dockerfile.website
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM python:latest
WORKDIR /home/plakplaats

# Install build dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libpq-dev gcc
RUN rm -rf /var/lib/apt/lists/*

# Install required python packages
COPY requirements.txt ./
RUN pip install -r requirements.txt --no-cache-dir

# Copy over remaining files
COPY . .

# Document which ports will be used
EXPOSE 3000

# Give a warm welcome
ENV SHELL="/bin/bash"
RUN echo "echo 'You are in the plakplaats devcontainer!'" >> /etc/bash.bashrc
RUN echo "echo 'Start the server with: python src/server.py'" >> /etc/bash.bashrc

# Do not run anything, but do not close the container either
CMD ["tail", "-f", "/dev/null"]
15 changes: 6 additions & 9 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
{
"name": "Plakplaats devcontainer",
"build": {
// Sets the run context to one level up instead of the .devcontainer folder.
"context": "..",
"dockerfile": "Dockerfile"
},
"forwardPorts": [
3000
],
"workspaceFolder": "/home/plakplaats",
"dockerComposeFile": "docker-compose.yml",
"service": "website-dev",
"forwardPorts": [3000],
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-azuretools.vscode-docker"
]
}
}
},
"runServices": ["website-dev"]
}
14 changes: 14 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Inherit but overwrite production configs with development configs

include:
- path: ../docker-compose.yml

services:
website-dev:
build:
context: ..
dockerfile: .devcontainer/Dockerfile.website
ports:
- "3000:3000"
depends_on:
- postgres_db
17 changes: 0 additions & 17 deletions Dockerfile

This file was deleted.

21 changes: 21 additions & 0 deletions Dockerfile.website
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:alpine
WORKDIR /home/plakplaats

# Install build dependencies
RUN apk add --no-cache postgresql-libs
RUN apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev

# Copy the files responsible for listing dependencies
COPY requirements.txt ./

# Cache the python dependencies
RUN python3 -m pip install -r requirements.txt --no-cache-dir

# Remove previously installed build dependencies, they are not needed anymore
RUN apk del .build-deps

# Copy the source code
COPY src src

EXPOSE 3000
CMD ["python", "src/server.py"]
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
services:
website:
build:
dockerfile: Dockerfile.website
ports:
- "3000:3000"
depends_on:
- postgres_db

postgres_db:
image: postgres:latest
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: plakplaats-db
ports:
- "5432:5432"

0 comments on commit e99d813

Please sign in to comment.