Skip to content

Dockerfile Rework #444

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

Draft
wants to merge 32 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
540310b
Datastore & Client AIO
Janmtbehrens May 13, 2025
5b70dcc
Implementing and testing Test-Image
Janmtbehrens May 19, 2025
e1e46e4
Dedicated Test-Script & Dev Folder
Janmtbehrens May 19, 2025
88fafa0
System-test now throws errors as expected
Janmtbehrens May 19, 2025
4e6e803
Production Build Support
Janmtbehrens May 20, 2025
09a44b0
Prod as default context & small bug fixes
Janmtbehrens May 22, 2025
b5bc638
Healthcheck Update
Janmtbehrens May 22, 2025
47a2cab
Bugfixes and Draft PR
Janmtbehrens May 22, 2025
7dfc0b8
Removed old Dockerfiles
Janmtbehrens Jun 2, 2025
2f6ea2e
Dockerfile Linting
Janmtbehrens Jun 3, 2025
749429e
Dependabot
Janmtbehrens Jun 5, 2025
868ac74
Merge remote-tracking branch 'upstream/main' into all-in-one
Janmtbehrens Jun 10, 2025
15bcef3
Adjust Workflows
Janmtbehrens Jun 12, 2025
63e33c3
Adjust Workflows #2
Janmtbehrens Jun 12, 2025
7d8b186
Adjust Workflows #3
Janmtbehrens Jun 12, 2025
934eb90
Dependabot compatibility issue fixed
Janmtbehrens Jun 12, 2025
dd5503e
Fix Workflow YAML Error
Janmtbehrens Jun 12, 2025
6d38e55
Workflow Fixes
Janmtbehrens Jun 12, 2025
a90f1a8
CHOWN removed as run-tests parameter and detach mode bug fix
Janmtbehrens Jun 12, 2025
b00529c
Hardcode chowning
Janmtbehrens Jun 12, 2025
0d4b710
Chown fix
Janmtbehrens Jun 12, 2025
32402d2
Mypy should ignore the dev folder
Janmtbehrens Jun 16, 2025
a2cc35b
Merge remote-tracking branch 'upstream/main' into all-in-one
Janmtbehrens Jun 16, 2025
df3b578
Remove old Dockerfiles
Janmtbehrens Jun 16, 2025
84b907c
Create unified and standardized continuous integration workflow for e…
Janmtbehrens Jun 17, 2025
996857f
Small fixes, Typos and Standards
Janmtbehrens Jun 17, 2025
580aff4
Adding a CI Job which executes run-tests.sh for all services
Janmtbehrens Jun 19, 2025
5b14f9f
Docker Compose files now all have build properties to automatically b…
Janmtbehrens Jun 19, 2025
48960c0
Lint scripts via Shellcheck
Janmtbehrens Jun 23, 2025
207a851
PR fixes
Janmtbehrens Jun 26, 2025
213eeda
PR fixes #2
Janmtbehrens Jun 26, 2025
4c738a4
Additional PR fixes
Janmtbehrens Jun 26, 2025
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
65 changes: 54 additions & 11 deletions .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Continuous Integration
name: CI - Build and Test Service

on:
pull_request:
branches:
Expand All @@ -13,8 +14,21 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Build container
run: make build
- name: Build Prod
uses: Janmtbehrens/OpenSlides/dev/actions/build-service@all-in-one
with:
service: datastore
context: prod
module: reader
port: 9010

- name: Build Prod
uses: Janmtbehrens/OpenSlides/dev/actions/build-service@all-in-one
with:
service: datastore
context: prod
module: writer
port: 9011

- name: Create secret
run: mkdir secrets && echo -n "openslides" > secrets/postgres_password
Expand All @@ -30,11 +44,18 @@ jobs:
- name: Test that writer is up and running
run: curl -I http://localhost:9011/

tests:
name: "Tests"
ci-tests:
name: "CI Tests"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build Tests
uses: Janmtbehrens/OpenSlides/dev/actions/build-service@all-in-one
with:
service: datastore
context: tests

- name: Execute tests
run: make run-ci

Expand All @@ -44,11 +65,33 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Start containers
run: make run-dev-standalone
- name: Build Dev
uses: Janmtbehrens/OpenSlides/dev/actions/build-service@all-in-one
with:
service: datastore
context: dev
module: reader
port: 9010

- name: Build Dev
uses: Janmtbehrens/OpenSlides/dev/actions/build-service@all-in-one
with:
service: datastore
context: dev
module: writer
port: 9011

- name: Execute tests
run: make run-full-system-tests-check
- name: Run System Tests
run: make ci-run-system-tests

# This setups and runs the dev/run-tests.sh script
run-test-script:
name: Run-tests.sh Script
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Stop tests
run: make stop-dev
- name: Run Test
uses: Janmtbehrens/OpenSlides/dev/actions/build-and-test-service@all-in-one
with:
service: datastore
109 changes: 89 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,109 @@
FROM python:3.10.17-slim-bookworm
ARG CONTEXT=prod

RUN apt-get -y update && apt-get -y upgrade && \
apt-get install --no-install-recommends -y ncat gcc libpq-dev libc-dev postgresql-client redis-tools cron
FROM python:3.10.17-slim-bookworm as base

## Setup
ARG CONTEXT
WORKDIR /app
ENV APP_CONTEXT=${CONTEXT}

## Install
RUN CONTEXT_INSTALLS=$(case "$APP_CONTEXT" in \
tests) echo "curl";; \
dev) echo "";; \
*) echo "cron" ;; esac) && \
apt-get -y update && apt-get -y upgrade && apt-get install --no-install-recommends -y \
gcc \
libc-dev \
libpq-dev \
ncat \
postgresql-client \
redis-tools \
${CONTEXT_INSTALLS} && \
rm -rf /var/lib/apt/lists/*

## Requirements
COPY requirements/* scripts/system/* scripts/* ./
RUN REQUIREMENTS_FILE=$(case "$APP_CONTEXT" in \
tests) echo "testing";; \
dev) echo "testing";; \
debug) echo "testing";; \
*) echo "general" ;; esac) && \
pip install --no-cache-dir -U -r requirements-${REQUIREMENTS_FILE}.txt

ENV PYTHONPATH /app/

COPY requirements/requirements-general.txt /app/
## External Information
LABEL org.opencontainers.image.title="OpenSlides Datastore Service"
LABEL org.opencontainers.image.description="Service for OpenSlides which wraps the database, which includes reader and writer functionality."
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.source="https://github.com/OpenSlides/openslides-datastore-service"

## Command
COPY ./dev/command.sh ./
RUN chmod +x command.sh
CMD ["./command.sh"]
HEALTHCHECK CMD python cli/healthcheck.py
ENTRYPOINT ["./entrypoint.sh"]

RUN pip install -U -r requirements-general.txt
# Testing Image

COPY cli cli
COPY datastore datastore
FROM base as tests

COPY scripts/* scripts/system/* tests/entrypoint.sh ./
COPY scripts/ci/* ./ci/
COPY dev ./dev/

STOPSIGNAL SIGKILL

# Intermediate Image

FROM base as moduled

ARG MODULE
RUN test -n "$MODULE" || (echo "MODULE not set" && false)
ENV MODULE=$MODULE

ARG PORT
RUN test -n "$PORT" || (echo "PORT not set" && false)
ENV PORT=$PORT

EXPOSE $PORT

ARG MODULE
RUN test -n "$MODULE" || (echo "MODULE not set" && false)
ENV MODULE=$MODULE
COPY $MODULE/entrypoint.sh ./

# Development Image

FROM moduled as dev

COPY scripts/system/* scripts/* ./

ENV FLASK_APP=datastore.$MODULE.app
ENV FLASK_DEBUG=1

# Debug Image

FROM moduled as debug

ENV FLASK_APP=datastore.$MODULE.app
ENV FLASK_DEBUG=1

# Production Image

FROM moduled as prod

# Add appuser
RUN adduser --system --no-create-home appuser && \
chown appuser /app/

COPY $MODULE/entrypoint.sh scripts/system/* ./
COPY cli cli
COPY datastore datastore

COPY scripts/system/* ./

ENV NUM_WORKERS=1
ENV WORKER_TIMEOUT=30

RUN echo "20 4 * * * root /app/cron.sh >> /var/log/cron.log 2>&1" > /etc/cron.d/trim-collectionfield-tables

LABEL org.opencontainers.image.title="OpenSlides Datastore Service"
LABEL org.opencontainers.image.description="Service for OpenSlides which wraps the database, which includes reader and writer functionality."
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.source="https://github.com/OpenSlides/openslides-datastore-service"

HEALTHCHECK CMD python cli/healthcheck.py

ENTRYPOINT ["./entrypoint.sh"]
CMD exec gunicorn -w $NUM_WORKERS -b 0.0.0.0:$PORT datastore.$MODULE.app:application -t $WORKER_TIMEOUT
USER appuser
28 changes: 0 additions & 28 deletions Dockerfile.debug

This file was deleted.

28 changes: 0 additions & 28 deletions Dockerfile.dev

This file was deleted.

17 changes: 0 additions & 17 deletions Dockerfile.test

This file was deleted.

47 changes: 33 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
SERVICE=datastore

# Build images for different contexts

build-dev:
bash ../dev/scripts/makefile/build-service.sh $(SERVICE) dev reader 9010
bash ../dev/scripts/makefile/build-service.sh $(SERVICE) dev writer 9011

build-prod:
bash ../dev/scripts/makefile/build-service.sh $(SERVICE) prod reader 9010
bash ../dev/scripts/makefile/build-service.sh $(SERVICE) prod writer 9011

build-test:
bash ../dev/scripts/makefile/build-service.sh $(SERVICE) tests

# TESTS

ifdef MODULE
Expand All @@ -9,10 +24,6 @@ build_args=--build-arg MODULE=$(MODULE) --build-arg PORT=$(PORT)
build:
docker build -t openslides-datastore-$(MODULE) $(build_args) .

# DEV
build-dev:
docker build -t openslides-datastore-$(MODULE)-dev -f Dockerfile.dev $(build_args) .

run-dev-standalone: | build-dev
docker compose -f dc.dev.yml up -d $(MODULE)

Expand All @@ -27,23 +38,26 @@ ifndef MODULE
## TESTS

build-tests:
docker build -t openslides-datastore-test -f Dockerfile.test .
make build-test

rebuild-tests:
docker build -t openslides-datastore-test -f Dockerfile.test . --no-cache
docker build . --tag=openslides-datastore-tests --no-cache --build-arg CONTEXT=tests

setup-docker-compose: | build-tests
setup-docker-compose: | build-tests-old
docker compose -f dc.test.yml up -d
docker compose -f dc.test.yml exec -T datastore bash -c "chown -R $$(id -u $${USER}):$$(id -g $${USER}) /app"

run-tests-no-down: | setup-docker-compose
docker compose -f dc.test.yml exec datastore ./entrypoint.sh pytest

run-tests: | run-tests-no-down
run-test:| run-tests-no-down
docker compose -f dc.test.yml down
@$(MAKE) run-dev
@$(MAKE) run-full-system-tests

run-tests:
bash dev/run-tests.sh

run-dev run-bash: | setup-docker-compose
docker compose -f dc.test.yml exec -u $$(id -u $${USER}):$$(id -g $${USER}) datastore ./entrypoint.sh bash

Expand All @@ -54,8 +68,8 @@ run-coverage: | setup-docker-compose
run-ci-no-down: | setup-docker-compose
docker compose -f dc.test.yml exec -T datastore ./entrypoint.sh ./execute-ci.sh

run-ci: | run-ci-no-down
docker compose -f dc.test.yml down
run-ci:
bash dev/run-ci.sh

run-cleanup: | setup-docker-compose
docker compose -f dc.test.yml exec -u $$(id -u $${USER}):$$(id -g $${USER}) datastore ./cleanup.sh
Expand Down Expand Up @@ -87,10 +101,10 @@ run-full-system-tests-check: | build-full-system-tests


# shared has no dev or prod image
build build-dev:
@$(MAKE) -C reader $@
@$(MAKE) -C writer $@

# This runs the target 'build' or 'build-dev' on the Makefile in the reader and writer subdirectory
#build build-dev:
# @$(MAKE) -C reader $@
# @$(MAKE) -C writer $@
run:
docker compose up -d

Expand All @@ -103,6 +117,11 @@ run-dev-standalone: | build-dev
run-dev-verbose: | build-dev
docker compose -f dc.dev.yml up

ci-run-system-tests:
docker compose -f dc.dev.yml up -d
make run-full-system-tests-check
make stop-dev

endif

# stopping is the same everywhere
Expand Down
Loading