From 7f9f88650d22254dee9a840f208aa568f7a7bf19 Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Fri, 12 Nov 2021 11:43:02 +0330 Subject: added a dev and deployment docker-compose --- Dockerfile | 7 ++++++- docker-compose-test.yaml | 45 +++++++++++++++++++++++++++++++++++++++++++++ docker-compose-travis.yaml | 32 -------------------------------- docker-compose.yaml | 2 ++ hived.go | 11 ++++++++++- 5 files changed, 63 insertions(+), 34 deletions(-) create mode 100644 docker-compose-test.yaml delete mode 100644 docker-compose-travis.yaml diff --git a/Dockerfile b/Dockerfile index 1cb0683..0a9e3e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,4 @@ FROM alpine:3.13 as builder - RUN apk update && apk upgrade RUN apk add go git COPY go.* /hived/ @@ -7,7 +6,13 @@ RUN cd /hived && go mod download COPY *.go /hived/ RUN cd /hived && go build +FROM node:lts-alpine3.13 AS certbuilder +RUN apk add openssl +WORKDIR /certs +RUN openssl req -nodes -new -x509 -subj="/C=US/ST=Denial/L=springfield/O=Dis/CN=localhost" -keyout server.key -out server.cert + FROM gcr.io/distroless/static-debian10 +COPY --from=certbuilder /cert/ /cert/ COPY --from=builder /hived/hived /hived/ COPY ./docker-entrypoint.sh /hived/ ENTRYPOINT ["/hived/docker-entrypoint.sh"] diff --git a/docker-compose-test.yaml b/docker-compose-test.yaml new file mode 100644 index 0000000..5040b2d --- /dev/null +++ b/docker-compose-test.yaml @@ -0,0 +1,45 @@ +version: "3.4" +services: + hived: + image: hived + build: + context: ./ + secrets: + - tg_bot_token + - ch_api_key + - ch_api_secret + networks: + - hivednet + restart: unless-stopped + ports: + - "8008:8008" + depends_on: + - redis + entrypoint: /hived/docker-entrypoint.sh + cap_drop: + - ALL + environment: + - SERVER_DEPLOYMENT_TYPE=test + redis: + image: redis:6.2-alpine + networks: + - hivednet + restart: unless-stopped + ports: + - "6379:6379" + environment: + - ALLOW_EMPTY_PASSWORD=yes + volumes: + - redis-data:/data/ +networks: + hivednet: + driver: bridge +secrets: + tg_bot_token: + file: ./tgtoken + ch_api_key: + file: ./changelly_api_key + ch_api_secret: + file: ./changelly_api_secret +volumes: + redis-data: diff --git a/docker-compose-travis.yaml b/docker-compose-travis.yaml deleted file mode 100644 index a5263e0..0000000 --- a/docker-compose-travis.yaml +++ /dev/null @@ -1,32 +0,0 @@ -version: "3.4" -services: - hived: - image: hived - build: - context: ./ - networks: - - hivednet - restart: unless-stopped - ports: - - "8008:8008" - depends_on: - - redis - entrypoint: /hived/hived - redis: - image: redis:6.2-alpine - networks: - - hivednet - restart: unless-stopped - ports: - - "6379:6379" - environment: - - ALLOW_EMPTY_PASSWORD=yes - volumes: - - redis-data:/data/ -networks: - hivednet: - driver: bridge - routenet: - driver: bridge -volumes: - redis-data: diff --git a/docker-compose.yaml b/docker-compose.yaml index 3be8194..ac7f223 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -20,6 +20,8 @@ services: - /etc/letsencrypt/archive/api.terminaldweller.com/:/certs/ cap_drop: - ALL + environment: + - SERVER_DEPLOYMENT_TYPE=deployment redis: image: redis:6.2-alpine networks: diff --git a/hived.go b/hived.go index 7924206..5345e70 100644 --- a/hived.go +++ b/hived.go @@ -44,6 +44,7 @@ const ( TELEGRAM_BOT_TOKEN_ENV_VAR = "TELEGRAM_BOT_TOKEN" CHANGELLY_API_KEY_ENV_VAR = "CHANGELLY_API_KEY" CHANGELLY_API_SECRET_ENV_VAR = "CHANGELLY_API_SECRET" + SERVER_DEPLOYMENT_TYPE = "SERVER_DEPLOYMENT_TYPE" ) func runTgBot() { @@ -628,7 +629,15 @@ func startServer(gracefulWait time.Duration) { r.HandleFunc("/crypto/robots.txt", robotsHandler) go func() { - if err := srv.ListenAndServeTLS("/certs/fullchain1.pem", "/certs/privkey1.pem"); err != nil { + var certPath, keyPath string + if os.Getenv(SERVER_DEPLOYMENT_TYPE) == "deployment" { + certPath = "/certs/fullchain1.pem" + keyPath = "/certs/privkey1.pem" + } else { + certPath = "/certs/server.cert" + keyPath = "/certs/server.key" + } + if err := srv.ListenAndServeTLS(certPath, keyPath); err != nil { log.Fatal().Err(err) } }() -- cgit v1.2.3