-
Notifications
You must be signed in to change notification settings - Fork 8
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
Changes from 19 commits
40190ad
93501fe
d4bcd3c
d3b1cf8
5ed7faa
798bbaf
8ffcfbd
b093657
b44bf53
ece9a9b
7ba76d5
fe4bf47
c9f045f
6752273
0f327a4
f49a433
2b6c32a
da86605
2b80ed7
59f7ab4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ lint: lint-python lint-go | |
.PHONY: vendor | ||
vendor: | ||
@echo "Fetching dependencies..." | ||
go mod vendor | ||
cd management-service && go mod vendor | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probabl also add commands to vendor the |
||
|
||
.PHONY: version | ||
version: | ||
|
@@ -171,7 +171,7 @@ build-treatment-service: version | |
build: build-management-service build-treatment-service | ||
|
||
.PHONY: build-image | ||
build-image: version | ||
build-image: version vendor | ||
@$(eval IMAGE_TAG = $(if $(DOCKER_REGISTRY),$(DOCKER_REGISTRY)/,)${BIN_NAME}:${VERSION}) | ||
@echo "Building docker image: ${IMAGE_TAG}" | ||
docker build --tag ${IMAGE_TAG} . | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package appcontext | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/pkg/errors" | ||
"gorm.io/gorm" | ||
|
||
|
@@ -30,36 +32,47 @@ func NewAppContext(db *gorm.DB, authorizer *mw.Authorizer, cfg *config.Config) ( | |
} | ||
|
||
// Init Services | ||
log.Println("Initializing message queue publisher...") | ||
messageQueueService, err := messagequeue.NewMessageQueueService(*cfg.MessageQueueConfig) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
log.Println("Initializing segmenter service...") | ||
segmenterSvc, err := services.NewSegmenterService(&allServices, cfg.SegmenterConfig, db) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
log.Println("Initializing validation service...") | ||
validationService, err := services.NewValidationService(cfg.ValidationConfig) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
log.Println("Initializing experiment history service...") | ||
experimentHistorySvc := services.NewExperimentHistoryService(db) | ||
log.Println("Initializing experiment service...") | ||
experimentSvc := services.NewExperimentService(&allServices, db) | ||
log.Println("Initializing project settings service...") | ||
projectSettingsSvc := services.NewProjectSettingsService(&allServices, db) | ||
|
||
log.Println("Initializing segment history service...") | ||
segmentHistorySvc := services.NewSegmentHistoryService(db) | ||
log.Println("Initializing segment service...") | ||
segmentSvc := services.NewSegmentService(&allServices, db) | ||
|
||
log.Println("Initializing treatment history service...") | ||
treatmentHistorySvc := services.NewTreatmentHistoryService(db) | ||
log.Println("Initializing treatment service...") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
treatmentSvc := services.NewTreatmentService(&allServices, db) | ||
|
||
mlpSvc, err := services.NewMLPService(cfg.MLPConfig.URL) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "Failed initializing MLP Service") | ||
} | ||
|
||
log.Println("Initializing configuration service...") | ||
configurationSvc := services.NewConfigurationService(cfg) | ||
|
||
allServices = services.NewServices( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,31 @@ | ||
FROM alpine:latest | ||
FROM golang:1.18-alpine as api-builder | ||
ARG API_BIN_NAME=xp-treatment | ||
|
||
RUN apk update && apk add musl-dev gcc | ||
|
||
ENV GO111MODULE=on \ | ||
GOOS=linux \ | ||
GOARCH=amd64 | ||
|
||
WORKDIR /app | ||
COPY . . | ||
|
||
RUN apk update && apk add git make bash unzip libtool gcc musl-dev ca-certificates dumb-init tzdata | ||
# Build Treatment Service binary | ||
RUN go build \ | ||
-mod=vendor \ | ||
-tags musl \ | ||
-o ./bin/${API_BIN_NAME} | ||
|
||
FROM alpine:latest | ||
|
||
RUN apk update && apk add git make bash unzip libtool ca-certificates dumb-init tzdata | ||
RUN mkdir -p /opt/xp_treatment | ||
|
||
COPY . /opt/xp_treatment/ | ||
COPY ./bin/* /opt/xp_treatment/ | ||
COPY --from=api-builder /app/bin/* /opt/xp_treatment/ | ||
|
||
WORKDIR /opt/xp_treatment | ||
ENTRYPOINT [ "./xp-treatment" ] | ||
|
||
ARG API_BIN_NAME=xp-treatment | ||
ENV XP_API_BIN "./${API_BIN_NAME}" | ||
|
||
ENTRYPOINT ["sh", "-c", "${XP_API_BIN} \"$@\"", "--"] |
There was a problem hiding this comment.
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?