Skip to content

Commit a17b954

Browse files
committed
feat: docker file for app and static
added static images creation and docker-compose example
1 parent 383a2c4 commit a17b954

File tree

6 files changed

+122
-31
lines changed

6 files changed

+122
-31
lines changed

.dockerignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,16 @@ sonar-project.properties
2424

2525
# Ignore current.py file to allow symbolic link creation during docker build
2626
orange/settings/current.py
27+
28+
assets/
29+
.venv/
30+
.env
31+
.github/
32+
.pre-commit-config.yaml
33+
.pytest_cache/
34+
Dockerfile
35+
LICENSE
36+
__pycache__/
37+
dict/
38+
docker/
39+
commitlint.config.js

.github/workflows/semver_build_publish.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,26 @@ jobs:
4949
steps:
5050
- name: Checkout
5151
uses: actions/checkout@v3
52-
- name: Build
52+
- name: Build app
5353
run: docker build . -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ needs.semver.outputs.version }}
54+
- name: Build Static
55+
run: docker build . --target static -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}-static:${{ needs.semver.outputs.version }}
5456
- name: Tag using channel
5557
run: |
5658
CHANNEL=${{ needs.semver.outputs.new_release_channel }}
5759
docker build . -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${CHANNEL:-'latest'}
60+
docker build . --target static -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}-static:${CHANNEL:-'latest'}
5861
- name: Login to Docker Hub
5962
run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
6063
- name: Push image
61-
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ needs.semver.outputs.version }}
64+
run: |
65+
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ needs.semver.outputs.version }}
66+
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}-static:${{ needs.semver.outputs.version }}
6267
- name: Push image on channel tag
6368
run: |
6469
CHANNEL=${{ needs.semver.outputs.new_release_channel }}
6570
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${CHANNEL:-'latest'}
71+
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}-static:${CHANNEL:-'latest'}
6672
6773
- name: Docker Hub Description
6874
uses: peter-evans/dockerhub-description@v3

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ celerybeat-schedule*
5757
# idea
5858
tmp/*
5959
.idea/*
60+
61+
assets/*

Dockerfile

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,54 @@
11
# base image
2-
FROM python:3.10.8-slim as python-base
2+
FROM python:3.10.8-alpine as python-base
33

4-
ENV PYTHONUNBUFFERED=1 \
4+
ENV PYTHONFAULTHANDLER=1 \
5+
PYTHONHASHSEED=random \
6+
PYTHONUNBUFFERED=1 \
57
PYTHONDONTWRITEBYTECODE=1 \
6-
PIP_NO_CACHE_DIR=off \
7-
PIP_DISABLE_PIP_VERSION_CHECK=on \
8-
PIP_DEFAULT_TIMEOUT=100 \
9-
POETRY_HOME="/opt/poetry" \
10-
POETRY_VIRTUALENVS_IN_PROJECT=true \
11-
POETRY_NO_INTERACTION=1 \
12-
APP_PATH="/app" \
13-
VENV_PATH="/app/.venv"
14-
15-
# prepend poetry and venv to path
16-
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"
17-
8+
VENV_PATH="/app/venv" \
9+
APP_PATH="/app"
10+
# prepend venv to path
11+
ENV PATH="$VENV_PATH/bin:$PATH"
1812
WORKDIR $APP_PATH
1913

2014

2115
# Build
2216
FROM python-base as builder-base
2317

24-
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
18+
SHELL ["/bin/ash", "-o", "pipefail", "-c"]
19+
20+
ENV PIP_DEFAULT_TIMEOUT=100 \
21+
PIP_DISABLE_PIP_VERSION_CHECK=1 \
22+
PIP_NO_CACHE_DIR=1
2523

2624
# get poetry
27-
# hadolint ignore=DL3008
28-
RUN apt-get update \
29-
&& apt-get --no-install-recommends install -y curl \
30-
&& apt-get clean \
31-
&& rm -rf /var/lib/apt/lists/* \
25+
RUN apk update \
26+
&& apk add --update --no-cache curl==7.87.0-r1 \
3227
&& curl -sSL https://install.python-poetry.org | python -
3328

34-
ENV PATH="${PATH}:/root/.poetry/bin"
29+
RUN python -m venv "$VENV_PATH"
30+
31+
ENV PATH="${PATH}:/root/.local/bin"
3532

3633

3734
COPY pyproject.toml poetry.lock ./
3835

39-
# install deps
40-
RUN poetry install --only main --no-root
36+
RUN poetry export -f requirements.txt | "$VENV_PATH/bin/pip" install -r /dev/stdin
37+
38+
COPY . .
39+
40+
RUN poetry build && "$VENV_PATH/bin/pip" install dist/*.whl \
41+
&& rm -rf dist/
42+
43+
44+
# Static base
45+
FROM builder-base as static-base
46+
47+
RUN python manage.py collectstatic
48+
49+
# Static
50+
FROM nginx:mainline-alpine as static
51+
COPY --from=static-base /app/assets /usr/share/nginx/html
4152

4253
# Prod
4354
FROM python-base as production

controller/settings.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
TESTING = sys.argv[1:2] == ["test"] or os.getenv("TESTING")
2929
ALLOWED_HOSTS = ["*"]
3030

31+
STATIC_URL = os.getenv("STATIC_URL", "/assets/static/")
32+
MEDIA_URL = os.getenv("MEDIA_URL", "/assets/media/")
33+
STATIC_ROOT = os.path.join(BASE_DIR, "assets/static")
34+
MEDIA_ROOT = os.path.join(BASE_DIR, "assets/media")
3135

3236
# Application definition
3337

@@ -151,12 +155,6 @@
151155

152156
USE_TZ = True
153157

154-
155-
# Static files (CSS, JavaScript, Images)
156-
# https://docs.djangoproject.com/en/4.1/howto/static-files/
157-
158-
STATIC_URL = "static/"
159-
160158
# Default primary key field type
161159
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
162160

docker/docker-compose.example.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
version: "3"
2+
3+
services:
4+
postgres:
5+
image: postgres:latest
6+
environment:
7+
- POSTGRES_DB=sentry
8+
- POSTGRES_USER=sentry
9+
- POSTGRES_PASSWORD=sentry
10+
ports:
11+
- 5432:5432
12+
volumes:
13+
- "controllerdata:/var/lib/postgresql/data"
14+
15+
redis:
16+
image: 'bitnami/redis:latest'
17+
environment:
18+
- ALLOW_EMPTY_PASSWORD=yes
19+
ports:
20+
- 6379:6379
21+
22+
static:
23+
image: spklabs/sentry-dynamic-sampling-controller-static:latest
24+
ports:
25+
- 8081:80
26+
app:
27+
image: spklabs/sentry-dynamic-sampling-controller:latest
28+
depends_on:
29+
- postgres
30+
- redis
31+
- static
32+
ports:
33+
- 8080:8000
34+
environment:
35+
- ENV=debug
36+
- SECRET_KEY="very_secret"
37+
- POSTGRES_DB=sentry
38+
- POSTGRES_USER=sentry
39+
- POSTGRES_PASSWORD=sentry
40+
- POSTGRES_HOST=postgres
41+
- POSTGRES_PORT=5432
42+
- APP_CACHE_TIMEOUT=600
43+
- CACHE_REDIS_URL=redis://redis:6379
44+
- CACHE_TIMEOUT=120
45+
- DEFAULT_SAMPLE_RATE=0.1
46+
- DEFAULT_WSGI_IGNORE_PATHS="/health,/healthz,/health/,/healthz/"
47+
- MAX_BUMP_TIME_SEC=6000
48+
# oidc
49+
- OIDC_RP_CLIENT_ID=$OIDC_RP_CLIENT_ID
50+
- OIDC_RP_CLIENT_SECRET=$OIDC_RP_CLIENT_SECRET
51+
- OIDC_OP_AUTHORIZATION_ENDPOINT=$OIDC_OP_AUTHORIZATION_ENDPOINT
52+
- OIDC_OP_TOKEN_ENDPOINT=$OIDC_OP_TOKEN_ENDPOINT
53+
- OIDC_OP_USER_ENDPOINT=$OIDC_OP_USER_ENDPOINT
54+
- LOGIN_REDIRECT_URL=$LOGIN_REDIRECT_URL
55+
- LOGOUT_REDIRECT_URL=$LOGOUT_REDIRECT_URL
56+
- OIDC_OP_JWKS_ENDPOINT=$OIDC_OP_JWKS_ENDPOINT
57+
- OIDC_RP_SIGN_ALGO=RS256
58+
- STATIC_URL=http://localhost:8081/static
59+
60+
volumes:
61+
controllerdata:

0 commit comments

Comments
 (0)