Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update docker files #672

Merged
merged 14 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
.coverage
.eslintcache
docker-compose-dev.yml
docker-compose.yml
Makefile.custom.config
*.log
data
data

**/__pycache__/
**/*.py[cod]
4 changes: 2 additions & 2 deletions .env.docker → .env.docker.dev
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export FLASK_SKIP_DOTENV=1
export APP_SETTINGS=fittrackee.config.DevelopmentConfig
export APP_SECRET_KEY='just for test'
# export APP_WORKERS=
export APP_LOG=fittrackee.log
export UPLOAD_FOLDER=/usr/src/app/uploads
export APP_LOG=/usr/src/app/data/logs/fittrackee.log
export UPLOAD_FOLDER=/usr/src/app/data/uploads

# PostgreSQL
export DATABASE_URL=postgresql://fittrackee:fittrackee@fittrackee-db:5432/fittrackee
Expand Down
44 changes: 44 additions & 0 deletions .env.docker.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Custom variables initialisation

# Docker volumes
# export UPLOAD_DIR=
# export LOG_DIR=
# export DATABASE_DIR=
# export REDIS_DIR=

# Application
export FLASK_APP=fittrackee
export FLASK_SKIP_DOTENV=1
# export APP_PORT=5000
export APP_SECRET_KEY='PLEASE CHANGE ME'
export APP_LOG=/usr/src/app/logs/fittrackee.log
export UPLOAD_FOLDER=/usr/src/app/uploads

# PostgreSQL
export POSTGRES_USER=fittrackee
export POSTGRES_PASSWORD=
export POSTGRES_DB=fittrackee
export DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@fittrackee-db:5432/${POSTGRES_DB}
# export DATABASE_DISABLE_POOLING=

# Redis (required for API rate limits and email sending)
export REDIS_URL=redis://redis:6379

# API rate limits
# export API_RATE_LIMITS="300 per 5 minutes"

# Emails
export UI_URL=
export EMAIL_URL=
export SENDER_EMAIL=

# Workouts
# export TILE_SERVER_URL=
# export STATICMAP_SUBDOMAINS=
# export MAP_ATTRIBUTION=
# export DEFAULT_STATICMAP=False

# Weather
# available weather API providers: visualcrossing
# export WEATHER_API_PROVIDER=
# export WEATHER_API_KEY=
66 changes: 66 additions & 0 deletions .github/workflows/.publish-docker-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Create and publish a Docker image

on:
push:
tags: ["v*"]

env:
GITHUB_REGISTRY: ghcr.io
GITHUB_IMAGE_NAME: ${{ github.repository }}

jobs:
push_to_registries:
name: Push Docker image to multiple registries
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.GITHUB_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
fittrackee/fittrackee
${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_IMAGE_NAME}}

- name: Build and push Docker images
id: push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Generate artifact attestation
uses: actions/attest-build-provenance@v2
with:
subject-name: ${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
67 changes: 48 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,51 @@
FROM python:3.10
FROM node:23-alpine AS node-builder

RUN mkdir -p /usr/src/app/fittrackee_client /usr/src/app/fittrackee
WORKDIR /usr/src/app/fittrackee_client

ENV PATH=/usr/src/app/fittrackee_client/node_modules/.bin:$PATH
COPY fittrackee_client/package.json /usr/src/app/fittrackee_client/package.json
COPY fittrackee_client/yarn.lock /usr/src/app/fittrackee_client/yarn.lock
RUN yarn install --silent --network-timeout 300000

COPY fittrackee_client/. /usr/src/app/fittrackee_client
RUN yarn build

FROM python:3.13-alpine AS python-builder

RUN mkdir -p /usr/src/app/
WORKDIR /usr/src/app/

ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 \
POETRY_VIRTUALENVS_CREATE=false \
POETRY_NO_INTERACTION=1 \
VIRTUAL_ENV=/opt/venv

COPY pyproject.toml poetry.lock README.md /usr/src/app/
COPY fittrackee/. /usr/src/app/fittrackee/
RUN rm -rf /usr/src/app/fittrackee/tests

RUN python3 -m venv $VIRTUAL_ENV && pip install --upgrade pip
RUN pip install poetry==1.8.5 && . $VIRTUAL_ENV/bin/activate && poetry install --only main --no-interaction --quiet

FROM python:3.13-alpine AS runtime

RUN apk add --no-cache tini

RUN addgroup -g 1000 -S fittrackee && \
adduser -H -D -u 1000 -S fittrackee -G fittrackee

# set working directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# copy source files
COPY . /usr/src/app

# install requirements
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN pip install --upgrade pip
RUN pip install poetry
RUN . $VIRTUAL_ENV/bin/activate && poetry install --no-interaction --quiet

# run fittrackee server
COPY ./docker-entrypoint.sh /docker-entrypoint.sh
COPY ./docker/set-admin.sh /usr/bin/set-admin
RUN chmod +x /usr/bin/set-admin && chmod +x /docker-entrypoint.sh
ENTRYPOINT [ "/docker-entrypoint.sh" ]
ENV VIRTUAL_ENV=/opt/venv PATH="/opt/venv/bin:$PATH"

COPY --chown=fittrackee --from=python-builder /opt/venv "$VIRTUAL_ENV"
COPY --chown=fittrackee --from=python-builder /usr/src/app/fittrackee /usr/src/app/fittrackee
COPY --chown=fittrackee --from=node-builder /usr/src/app/fittrackee/dist /usr/src/app/fittrackee/dist
COPY --chown=fittrackee docker-entrypoint.sh /usr/src/app/

RUN chmod 555 /usr/src/app/docker-entrypoint.sh

USER fittrackee

ENTRYPOINT ["/sbin/tini", "--"]
22 changes: 22 additions & 0 deletions Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM python:3.13-slim

# set working directory
RUN mkdir -p /usr/src/app/data/uploads /usr/src/app/data/logs
WORKDIR /usr/src/app

# copy source files
COPY . /usr/src/app

# install requirements
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN pip install --upgrade pip
RUN pip install poetry
RUN . $VIRTUAL_ENV/bin/activate && poetry install --no-interaction --quiet

# run fittrackee server and workers
COPY ./docker-entrypoint-dev.sh /docker-entrypoint.sh
COPY ./docker/set-admin.sh /usr/bin/set-admin
RUN chmod +x /usr/bin/set-admin && chmod +x /docker-entrypoint.sh
ENTRYPOINT [ "/docker-entrypoint.sh" ]
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ docker-lint-client:
docker compose -f docker-compose-dev.yml exec fittrackee_client $(NPM) type-check

docker-lint-python: docker-run
docker compose -f docker-compose-dev.yml exec fittrackee docker/lint-python.sh
docker compose -f docker-compose-dev.yml exec fittrackee mypy fittrackee
docker compose -f docker-compose-dev.yml exec fittrackee ruff check fittrackee e2e

docker-logs:
docker compose -f docker-compose-dev.yml logs --follow
Expand Down Expand Up @@ -95,7 +96,7 @@ docker-set-admin:
docker compose -f docker-compose-dev.yml exec fittrackee ftcli users update $(USERNAME) --set-admin true

docker-shell:
docker compose -f docker-compose-dev.yml exec fittrackee docker/shell.sh
docker compose -f docker-compose-dev.yml exec fittrackee /bin/bash

docker-stop:
docker compose -f docker-compose-dev.yml stop
Expand All @@ -114,7 +115,7 @@ docker-test-e2e: docker-run
docker compose -f docker-compose-dev.yml exec fittrackee docker/test-e2e.sh $(PYTEST_ARGS)

docker-test-python: docker-run
docker compose -f docker-compose-dev.yml exec fittrackee docker/test-python.sh $(PYTEST_ARGS)
docker compose -f docker-compose-dev.yml exec fittrackee pytest fittrackee $(PYTEST_ARGS)

docker-type-check:
echo 'Running mypy in docker...'
Expand Down
16 changes: 11 additions & 5 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# docker compose for evaluation and development only
# not suitable for production

services:
fittrackee-db:
container_name: fittrackee-db
image: postgres:13
image: postgres:17-alpine
ports:
- "5435:5432"
environment:
Expand All @@ -18,11 +21,13 @@ services:

fittrackee:
container_name: fittrackee
build: .
build:
context: .
dockerfile: Dockerfile-dev
ports:
- "5000:5000"
env_file:
- .env
- .env.docker.dev
depends_on:
fittrackee-db:
condition: service_healthy
Expand All @@ -32,7 +37,8 @@ services:
condition: service_started
volumes:
- .:/usr/src/app
- ./data/uploads:/usr/src/app/uploads
- ./data/uploads:/usr/src/app/data/uploads
- ./data/logs:/usr/src/app/data/logs

fittrackee_client:
container_name: fittrackee_client
Expand All @@ -54,7 +60,7 @@ services:

redis:
container_name: fittrackee-redis
image: "redis:latest"
image: "redis:7.4"
hostname: redis
ports:
- "6379:6379"
Expand Down
Loading
Loading