Skip to content

Dockerfile Rework #1205

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

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open

Conversation

Janmtbehrens
Copy link

Reworked Dockerfile & Makefiles, so that there is one singular Dockerfile that supports development, testing and production images.
Also adding features like healthchecks and use of restricted app users, as well as fixing some bugs

@Janmtbehrens Janmtbehrens marked this pull request as ready for review June 5, 2025 07:26
@Janmtbehrens Janmtbehrens marked this pull request as draft June 5, 2025 07:27
@rrenkert rrenkert requested a review from ostcar July 3, 2025 14:52
@Janmtbehrens Janmtbehrens marked this pull request as ready for review July 3, 2025 15:14
with:
service: autoupdate

readme-validation:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is anything beneath needed? I created the workflows/readme.yml to test commands in the readme. But the readme needs to be cleaned up. I can do this after this PR is merged. Afterwards, I will cleanup this part to be the same as in the readme. Is this ok for your concept?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether readme-validation is needed or not I can't evaluate. The goal with this PR is mainly to standardize Dockerfiles and their associated Files. Since readme-validation also builds Images based on these Images, I had to make changes here too. While at it I aggregated all CI related Workflows into a single Workflow File for better overview, since they had obscure names before that didn't properly reflect their purpose.

The readme and therefore the readme-validation may very well needs to be updated and you are free to do so and change whatever you want about the contents of this workflow after this PR merged, though I'd like to review these changes to some degree if possible

@@ -1,46 +1,65 @@
ARG CONTEXT=prod
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line has no effect. It is in the global scope and gets reset at FROM. See https://docs.docker.com/build/building/variables/#scoping

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not entirely true, it sets the default value for CONTEXT to be prod, so that the default target context is the production image. It will get reset with the next FROM, but because of the Line 6 'ARG CONTEXT' this global variable gets 'consumed' and is available for the build stage.
This was implemented with the intention that multiple different build stages can point to the same default value defined at the start of the Dockerfile instead of having multiple different default value declarations in the Dockerfile for each build stage. It may be unnecessarily verbose and is not specifically necessary for autoupdate, but I still do it like so here to uphold the same Dockerfile structure across all Services

ARG CONTEXT

WORKDIR /app/openslides-autoupdate-service
ENV APP_CONTEXT=${CONTEXT}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? The autoupdate-service does not read this environment variable

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new standard variable that is set in every Dockerfile of each Service. It can be used to 'know' in what context you currently operate it and should absolve environment variables like OPENSLIDES_DEVELOPMENT.
It might not be necessary for autoupdate in specific, but it should still be there to have it available if needed.

# Test build.
FROM base as testing
## Healthcheck
HEALTHCHECK CMD ["/app/openslides-autoupdate-service/openslides-autoupdate-service", "health"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LABEL, EXPOSE and HEALTHCHECK defintions are confusing. In this current implementation, they are inherited to dev and tests but not to prod. tests does not need them, so the definition here is actually only used in dev.

Please move them to dev to make be more clear


# Productive build
FROM scratch
WORKDIR /
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line has no effect and should be removed.

The prod image is FROM scratch. It does not inherit any values from other images. The default value for WORKDIR is /

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is best practice to always declare the Workdir, even if it is /

# Productive build
FROM scratch
WORKDIR /
ENV APP_CONTEXT=prod
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this line. The autoupdate service never reads this variable

build-dev:
docker build . --target development --tag openslides-autoupdate-dev
bash ../dev/scripts/makefile/build-service.sh $(SERVICE) dev
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like this. The autoupdate-service is its own repo. This line expects to be called from the main repo. But if this line can only be called from the context of the main repo, this file should only exist in the main repo.

Please change the Makefile, so it also works, if only the autoupdate-service is checked out

mkdir only-autoupdate
cd only-autoupdate
git clone https://github.com/OpenSlides/openslides-autoupdate-service.git
cd openslides-autoupdate-service
make build-dev

The same for every other command in this file

@@ -0,0 +1,22 @@
#!/bin/bash

# Executes all tests. Should errors occur, CATCH will be set to 1, causing an erroneous exit code.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is wrong. This file does not call all tests but only the tests, that does not need postgres.

Please make sure, that this script should not be used, if all tests should run

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is intended to run all tests. Can you please tell me which test commands are missing so that I can add them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants