From 45614e1aa54957086592674141d3ba726fa3b63c Mon Sep 17 00:00:00 2001 From: ShiKhu Date: Tue, 20 Jul 2021 21:51:03 +0800 Subject: [PATCH] feat(backend): one-image dockerfile --- backend/Dockerfile | 31 +++++++++++++++--------- backend/{Dockerfile-all => Dockerfile-1} | 31 +++++++++++------------- backend/go.mod | 1 + 3 files changed, 35 insertions(+), 28 deletions(-) rename backend/{Dockerfile-all => Dockerfile-1} (51%) diff --git a/backend/Dockerfile b/backend/Dockerfile index 45b435398..06fce36bc 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.13-alpine AS build +FROM golang:1.13-alpine3.10 AS build RUN apk add --no-cache git openssh openssl-dev pkgconf gcc g++ make libc-dev bash @@ -8,15 +8,15 @@ COPY . . RUN go mod download -ARG SERVICE_NAME -RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o service -tags musl openreplay/backend/services/$SERVICE_NAME + +RUN for name in alerts assets db ender http integrations sink storage;do CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o bin/$name -tags musl openreplay/backend/services/$name; done FROM alpine RUN apk add --no-cache ca-certificates ENV TZ=UTC \ FS_ULIMIT=1000 \ - FS_DIR=/mnt/efs \ + FS_DIR=/filestorage \ MAXMINDDB_FILE=/root/geoip.mmdb \ UAPARSER_FILE=/root/regexes.yaml \ HTTP_PORT=80 \ @@ -36,14 +36,23 @@ ENV TZ=UTC \ AWS_REGION_IOS=eu-west-1 \ AWS_REGION_ASSETS=eu-central-1 \ CACHE_ASSETS=false \ - ASSETS_SIZE_LIMIT=6291456 + ASSETS_SIZE_LIMIT=6291456 \ + FS_CLEAN_HRS=12 -ARG SERVICE_NAME -RUN if [ "$SERVICE_NAME" = "http" ]; then \ - wget https://raw.githubusercontent.com/ua-parser/uap-core/master/regexes.yaml -O "$UAPARSER_FILE" &&\ - wget https://static.openreplay.com/geoip/GeoLite2-Country.mmdb -O "$MAXMINDDB_FILE"; fi +RUN mkdir $FS_DIR +RUN wget https://raw.githubusercontent.com/ua-parser/uap-core/master/regexes.yaml -O "$UAPARSER_FILE" &&\ + wget https://static.openreplay.com/geoip/GeoLite2-Country.mmdb -O "$MAXMINDDB_FILE" -COPY --from=build /root/service /root/service -ENTRYPOINT /root/service +COPY --from=build /root/bin /root/bin + +#ENTRYPOINT /root/bin/http + +ENV TINI_VERSION v0.19.0 +ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini +RUN chmod +x /tini +ENTRYPOINT ["/tini", "--"] + + +CMD for name in alerts assets db ender http integrations sink storage;do nohup bin/$name &> /tmp/${name}.log ; done diff --git a/backend/Dockerfile-all b/backend/Dockerfile-1 similarity index 51% rename from backend/Dockerfile-all rename to backend/Dockerfile-1 index d56dcbf23..477db218e 100644 --- a/backend/Dockerfile-all +++ b/backend/Dockerfile-1 @@ -1,4 +1,4 @@ -FROM golang:1.13-alpine AS build +FROM golang:1.13-alpine3.10 AS build RUN apk add --no-cache git openssh openssl-dev pkgconf gcc g++ make libc-dev bash @@ -8,15 +8,15 @@ COPY . . RUN go mod download - -RUN for name in alerts assets db ender http integrations sink storage;do CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o bin/$name -tags musl openreplay/backend/services/$name; done +ARG SERVICE_NAME +RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o service -tags musl openreplay/backend/services/$SERVICE_NAME FROM alpine RUN apk add --no-cache ca-certificates ENV TZ=UTC \ FS_ULIMIT=1000 \ - FS_DIR=/filestorage \ + FS_DIR=/mnt/efs \ MAXMINDDB_FILE=/root/geoip.mmdb \ UAPARSER_FILE=/root/regexes.yaml \ HTTP_PORT=80 \ @@ -35,19 +35,16 @@ ENV TZ=UTC \ AWS_REGION_WEB=eu-central-1 \ AWS_REGION_IOS=eu-west-1 \ AWS_REGION_ASSETS=eu-central-1 \ - CACHE_ASSETS=true \ - ASSETS_SIZE_LIMIT=6291456 - -RUN mkdir $FS_DIR -RUN wget https://raw.githubusercontent.com/ua-parser/uap-core/master/regexes.yaml -O "$UAPARSER_FILE" &&\ - wget https://static.openreplay.com/geoip/GeoLite2-Country.mmdb -O "$MAXMINDDB_FILE" - -COPY --from=build /root/bin /root/bin + CACHE_ASSETS=false \ + ASSETS_SIZE_LIMIT=6291456 \ + FS_CLEAN_HRS=0 -ENV TINI_VERSION v0.19.0 -ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini -RUN chmod +x /tini -ENTRYPOINT ["/tini", "--"] +ARG SERVICE_NAME +RUN if [ "$SERVICE_NAME" = "http" ]; then \ + wget https://raw.githubusercontent.com/ua-parser/uap-core/master/regexes.yaml -O "$UAPARSER_FILE" &&\ + wget https://static.openreplay.com/geoip/GeoLite2-Country.mmdb -O "$MAXMINDDB_FILE"; fi -CMD for name in alerts assets db ender http integrations sink storage; nohup bin/$name &> /tmp/${name}.log + +COPY --from=build /root/service /root/service +ENTRYPOINT /root/service diff --git a/backend/go.mod b/backend/go.mod index 2729bcccc..3c93fd20b 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -17,5 +17,6 @@ require ( github.com/ua-parser/uap-go v0.0.0-20200325213135-e1c09f13e2fe gopkg.in/confluentinc/confluent-kafka-go.v1 v1.5.2 github.com/ClickHouse/clickhouse-go v1.4.3 + github.com/Masterminds/squirrel v1.5.0 github.com/aws/aws-sdk-go v1.35.23 )