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

Support multi-stage builds for Management & Treatment Services Dockerfile #66

Merged
merged 20 commits into from
Mar 14, 2023

Conversation

terryyylim
Copy link
Contributor

@terryyylim terryyylim commented Mar 6, 2023

What this PR does / why we need it:

When updating the helm chart for XP Management Service caraml-dev/helm-charts#220, Permission Denied error was faced when trying to run the generated binary.

Subsequently, we're faced with Exec format error which points to our binary file being built on Ubuntu and to be used in an Alpine image. This PR adds multi-stage builds to build our app binaries using an Alpine image and copied over to the latest layer of our Docker image to solve the issue and also make the image leaner.

Which issue(s) this PR fixes:

Fixes #

@terryyylim terryyylim self-assigned this Mar 6, 2023
@terryyylim terryyylim marked this pull request as ready for review March 6, 2023 09:42
@terryyylim terryyylim requested a review from a team March 6, 2023 09:50
Dockerfile Outdated
@@ -21,6 +21,8 @@ RUN addgroup -S ${XP_USER_GROUP} \

COPY --chown=${XP_USER}:${XP_USER_GROUP} management-service/bin/* /app/
COPY --chown=${XP_USER}:${XP_USER_GROUP} management-service/database /app/database/
# read+write access for owner/group but no write access for others
RUN chmod -R 775 /app/xp-management
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • Not sure if the chmod has some unintended impact. Are we still able to build and deploy the internal image on top of this? Can it be tested prior to merging this?
  • Do we need a similar change for the treatment service too?

@terryyylim terryyylim changed the title Update Management Service Dockerfile Support multi-stage builds for Management & Treatment Services Dockerfile Mar 10, 2023
@terryyylim terryyylim force-pushed the update-docker-image-perms branch 3 times, most recently from 92227ed to e55a5ca Compare March 11, 2023 03:32
Copy link
Collaborator

@krithika369 krithika369 left a comment

Choose a reason for hiding this comment

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

Left some small comments, the rest LGTM. Thanks @terryyylim !

Dockerfile Outdated
@@ -19,8 +35,10 @@ RUN addgroup -S ${XP_USER_GROUP} \
&& mkdir /app \
&& chown -R ${XP_USER}:${XP_USER_GROUP} /app

COPY --chown=${XP_USER}:${XP_USER_GROUP} management-service/bin/* /app/
COPY --chown=${XP_USER}:${XP_USER_GROUP} management-service/database /app/database/
COPY --chown=${XP_USER}:${XP_USER_GROUP} management-service/bin/experiments.yaml /app/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Can we do COPY --chown=${XP_USER}:${XP_USER_GROUP} management-service/bin/*.yaml /app/ instead of 2 separate commands to copy the OpenAPI specs?

@@ -34,7 +34,7 @@ lint: lint-python lint-go
.PHONY: vendor
vendor:
@echo "Fetching dependencies..."
go mod vendor
cd management-service && go mod vendor
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should probabl also add commands to vendor the common and clients modules before vendoring the management service.

treatmentHistorySvc := services.NewTreatmentHistoryService(db)
log.Println("Initializing treatment service...")
Copy link
Collaborator

Choose a reason for hiding this comment

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

These seem like Debug logs. It would be enough to just have error logs if the initialization fails. Alternatively, if we want to keep these logs, we should log them at the appropriate level.

@terryyylim terryyylim merged commit 12e2691 into caraml-dev:main Mar 14, 2023
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.

None yet

2 participants