Skip to content

Commit

Permalink
Merge pull request #8 from chnm/feature/dockerize
Browse files Browse the repository at this point in the history
Merge feature/dockerize into main
  • Loading branch information
hepplerj authored Nov 6, 2024
2 parents 6b4f1df + f8f1054 commit 87fff5d
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 32 deletions.
56 changes: 56 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
FROM rust as volta-build
WORKDIR /src
RUN git clone https://github.com/volta-cli/volta.git /src
RUN cargo build
RUN ls /src/target/debug

# Pull base image for Python 3.11
FROM python:3.11

# Set environment variables
ENV PIP_DISABLE_PIP_VERSION_CHECK 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set working directory
WORKDIR /app

# Copy project
COPY . /app/

# Install dependencies with Poetry
RUN pip3 install poetry

RUN poetry config virtualenvs.create false
RUN poetry install --no-root

# Copy over Volta binaries
RUN mkdir -p /root/.volta/bin
COPY --from=volta-build /src/target/debug/volta /root/.volta/bin
COPY --from=volta-build /src/target/debug/volta-migrate /root/.volta/bin
COPY --from=volta-build /src/target/debug/volta-shim /root/.volta/bin

# shell stuff for volta
SHELL ["/bin/bash", "-c"]
ENV BASH_ENV ~/.bashrc
ENV VOLTA_HOME /root/.volta
ENV PATH $VOLTA_HOME/bin:$PATH

RUN ln -s /root/.volta/bin/volta-shim /root/.volta/bin/node
RUN ln -s /root/.volta/bin/volta-shim /root/.volta/bin/npm
RUN ln -s /root/.volta/bin/volta-shim /root/.volta/bin/npx
RUN ln -s /root/.volta/bin/volta-shim /root/.volta/bin/pnpm
RUN ln -s /root/.volta/bin/volta-shim /root/.volta/bin/yarn

# triggers node installation
RUN node -v && npm -v
RUN npm install

# generate front end assets
RUN poetry run python manage.py tailwind install
RUN poetry run python manage.py tailwind build
RUN poetry run python manage.py collectstatic --no-input

# clean up
RUN rm -rf /root/.volta
RUN rm -rf /app/node_modules
10 changes: 8 additions & 2 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env("DEBUG")
SECRET_KEY = env("DJANGO_SECRET_KEY")

ALLOWED_HOSTS = []
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = env(
"DJANGO_SECRET_KEY",
default="django-insecure _&4l$xw8b*--m5lpq8$9f4e-nf^tr5y^5pvfwj#eui=7$fnxpg",
)

ALLOWED_HOSTS = env.list("DJANGO_ALLOWED_HOSTS", default=["localhost"])

# Application definition

Expand Down
45 changes: 45 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
name: graffitihouse

services:
app:
build: .
image: "rrchnm/graffitihouse"
ports:
- 8000:8000
volumes:
- dj-data:/app
environment:
- DEBUG=True
- DJANGO_SECRET_KEY=thisisnotasecretkey
- DJANGO_ALLOWED_HOSTS=localhost
- DJANGO_CSRF_TRUSTED_ORIGINS=http://localhost
- DB_HOST=db
- DB_PORT=5432
- DB_NAME=graffitihouse
- DB_USER=graffitihouse
- DB_PASSWORD=password
command: >
sh -c "poetry run python3 manage.py migrate &&
poetry run python3 manage.py runserver 0.0.0.0:8000"
depends_on:
db:
condition: service_healthy
db:
image: postgres:16
volumes:
- pg-data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=graffitihouse
- POSTGRES_USER=graffitihouse
- POSTGRES_PASSWORD=password
- POSTGRES_HOST=db
healthcheck:
test: ["CMD-SHELL", "pg_isready -U graffitihouse"]
interval: 2s
timeout: 5s
retries: 3

volumes:
pg-data:
dj-data:
84 changes: 84 additions & 0 deletions docker-compose.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# this is a Jinja2 template file used during the Ansible deployment
# environment specific configuration can be found in our Ansble scripts
---
name: {{ compose_stack_name }}

services:

{% set service = 'app' %}

app:
image: ghcr.io/{{ template.git.package.image_name }}:{{ template.git.package.tag }}
restart: unless-stopped
ports:
- "{{ template.env.host_app_port }}:8000"
environment:
- DEBUG={{ template.env.debug_flag }}
- DJANGO_SECRET_KEY={{ template.env.secret_key }}
- DJANGO_ALLOWED_HOSTS={{ template.env.allowed_hosts }}
- DJANGO_CSRF_TRUSTED_ORIGINS={{ template.env.trusted_origins }}
- DB_HOST=db
- DB_PORT={{ template.env.host_db_port }}
- DB_NAME={{ template.env.db_name }}
- DB_USER={{ template.env.db_user }}
- DB_PASS={{ template.env.db_pass }}
- OBJ_STORAGE={{ template.env.obj_storage }}
- OBJ_STORAGE_ACCESS_KEY_ID={{ template.env.obj_storage_access_key_id }}
- OBJ_STORAGE_SECRET_ACCESS_KEY={{ template.env.obj_storage_secret_access_key }}
- OBJ_STORAGE_BUCKET_NAME={{ template.env.obj_storage_bucket_name }}
- OBJ_STORAGE_ENDPOINT_URL={{ template.env.obj_storage_endpoint_url }}
command: >
sh -c "poetry run python3 manage.py migrate &&
poetry run python3 manage.py runserver 0.0.0.0:8000"
{% if template.volumes is defined %}
{% set vols = (template.volumes | selectattr('service', 'eq', service)) %}
{% if vols is iterable and vols | length > 0 %}

volumes:
{% for vol in vols %}

- {{ vol.name }}:{{ vol.container_path }}
{% endfor %}
{% endif %}
{% endif %}

depends_on:
db:
condition: service_healthy

{% set service = 'db' %}

db:
image: postgres:12
restart: unless-stopped
environment:
- POSTGRES_DB={{ template.env.db_name }}
- POSTGRES_USER={{ template.env.db_user }}
- POSTGRES_PASSWORD={{ template.env.db_pass }}
- POSTGRES_HOST=db
{% if template.volumes is defined %}
{% set vols = (template.volumes | selectattr('service', 'eq', service)) %}
{% if vols is iterable and vols | length > 0 %}

volumes:
{% for vol in vols %}

- {{ vol.name }}:{{ vol.container_path }}
{% endfor %}
{% endif %}
{% endif %}

healthcheck:
test: ["CMD-SHELL", "pg_isready -U {{ template.env.db_user }}"]
interval: 5s
timeout: 5s
retries: 5

# external volumes managed and defined by ansible
volumes:
{% for vol in template.volumes %}

{{ vol.name }}:
name: "{{ compose_stack_name }}--{{ vol.name }}"
external: true
{% endfor %}
62 changes: 32 additions & 30 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions theme/static_src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
"postcss-simple-vars": "^7.0.1",
"rimraf": "^4.1.2",
"tailwindcss": "^3.2.7"
},
"volta": {
"extends": "../../package.json"
}
}

0 comments on commit 87fff5d

Please sign in to comment.