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

Dockerfile and docker-compose.yaml to deploy container, and workflow to automatically build new images on master branch #654

Closed
wants to merge 3 commits into from
Closed
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
68 changes: 68 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Create and publish a Docker image

# Configures this workflow to run every time a change is pushed to the branch called `release`.
on:
push:
branches: ["master"]
tags: ["v*"]
workflow_dispatch:

# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
jobs:
build-and-push-image:
runs-on: ubuntu-latest
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
id-token: write
#
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set BUILD_TIME env
run: echo BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") >> ${GITHUB_ENV}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=semver,pattern=release
type=sha
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
push: true
build-args: |
BUILD_TIME=${{ env.BUILD_TIME }}
GIT_COMMIT=${{ github.sha }}
GIT_REF=${{ github.ref }}
GIT_REF_NAME=${{ github.ref_name }}
GIT_REF_TYPE=${{ github.ref_type }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
52 changes: 40 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,50 @@
FROM python:3.10
FROM python:3.13-alpine AS BUILDER

# set working directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# install dependencies
RUN apk add --no-cache linux-headers gcc musl-dev libffi-dev \
--virtual=build-dependencies
RUN apk add --no-cache py-pip bash curl

# copy source files
COPY . /usr/src/app
RUN LATEST=$(curl -s \
"https://api.github.com/repos/SamR1/FitTrackee/releases/latest" | \
grep -i zipball_url | grep -Eo "https://.*[0-9]{1}") && \
wget "${LATEST}" -O /usr/src/latest.zip
RUN cd /usr/src/ && unzip latest.zip -d /usr/src/app
RUN sync
RUN mv /usr/src/app/*FitTrackee*/* /usr/src/app/
RUN rm -r /usr/src/app/*FitTrackee*/
RUN rm -r /usr/src/latest.zip

# install requirements
WORKDIR /usr/src/app
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 pip install --no-cache-dir --upgrade pip
RUN pip install --no-cache-dir poetry
RUN . $VIRTUAL_ENV/bin/activate && poetry install --no-interaction


FROM python:3.13-alpine

RUN apk add bash

# create user fittrackee
RUN addgroup -g 1000 -S fittrackee
RUN adduser -u 1000 -S -D -G fittrackee -H -h /usr/src/app -s /bin/bash fittrackee

COPY --from=BUILDER /opt/venv/ /opt/venv
COPY --from=BUILDER /usr/src/app /usr/src/app

WORKDIR /usr/src/app
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# change owner
RUN chown -R fittrackee:fittrackee /usr/src/app

# 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" ]
USER fittrackee
CMD flask run --with-threads -h 0.0.0.0
57 changes: 57 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
version: "3.1"
services:
fittrackee:
image: ghcr.io/davidhenrythoreau/fittrackee:master
container_name: fittrackee
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/Paris
- FLASK_DEBUG=1
- FLASK_APP=fittrackee/__main__.py
- FLASK_SKIP_DOTENV=1
- APP_SETTINGS=fittrackee.config.ProductionConfig
- APP_SECRET_KEY='just for test'
- UPLOAD_FOLDER=/usr/src/app/uploads
- DATABASE_URL=postgresql://fittrackee:fittrackee@fittrackee-db:5432/fittrackee
- DATABASE_TEST_URL=postgresql://fittrackee:fittrackee@fittrackee-db:5432/fittrackee_test
- REDIS_URL=redis://fittrackee-redis:6379
volumes:
- ./fittrackee-upload:/usr/src/app/uploads/uploads/
ports:
- 8230:5000
depends_on:
fittrackee-db:
condition: service_started
fittrackee-redis:
condition: service_started
command: bash -c "cd /usr/src/app && ftcli db upgrade && flask run --with-threads -h 0.0.0.0"
restart: unless-stopped

fittrackee-db:
image: postgres:17-alpine
container_name: fittrackee-db
environment:
- PUID=70
- PGID=70
- TZ=Europe/Paris
- POSTGRES_USER=fittrackee
- POSTGRES_PASSWORD=fittrackee
- POSTGRES_DB=fittrackee
volumes:
- ./fittrackee-db:/var/lib/postgresql/data
ports:
- 5432:5432
restart: unless-stopped

fittrackee-redis:
image: redis:latest
container_name: fittrackee-redis
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/Paris
ports:
- 6379:6379
restart: unless-stopped
Loading