From 0704081466a939037cae96eddbd3b043ad76053a Mon Sep 17 00:00:00 2001 From: Sawood Alam Date: Fri, 27 Oct 2017 16:37:05 -0400 Subject: [PATCH 1/6] Docker workflow improvemnet --- Dockerfile | 6 +++--- docker-compose.yml | 17 ++++++++--------- sample.env | 4 ++++ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index b1a435e..f3f0f12 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,11 +15,11 @@ WORKDIR /go/src/github.com/datatogether/coverage # Run tests RUN go test -# Build the static api binary +# Build the static api binary for production RUN CGO_ENABLED=0 GOOS=linux go install -a -installsuffix cgo -# Let gin watch and build by default in development environment -CMD ["gin", "-i"] +# Set binary as the default command +CMD ["coverage"] # Start over from an Alpine Linux image as a base # to create a minumal production image diff --git a/docker-compose.yml b/docker-compose.yml index 5fe0b8f..5979a84 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,22 +1,21 @@ -version: '2' +version: '2.3' services: coverage: - build: . + build: + context: . + target: dev + env_file: .env volumes: - .:/go/src/github.com/datatogether/coverage - ./sql:/sql ports: - - $PORT:$PORT + - "$PORT:$PORT" + - "3000:3000" networks: - back-tier depends_on: - postgres - environment: - - PORT=$PORT - - TLS=false - - GOLANG_ENV=develop - - POSTGRES_DB_URL=postgres://postgres@postgres/postgres?sslmode=disable - - RPC_PORT=4400 + command: gin -i -p 3000 -a $PORT postgres: image: "postgres:9.6-alpine" networks: diff --git a/sample.env b/sample.env index 25241b7..0ef61f6 100644 --- a/sample.env +++ b/sample.env @@ -1 +1,5 @@ PORT=8080 +RPC_PORT=4400 +TLS=false +GOLANG_ENV=develop +POSTGRES_DB_URL=postgres://postgres@postgres/postgres?sslmode=disable From d90528cc8cd05bd23ca4511acb8662e2a5fd5adc Mon Sep 17 00:00:00 2001 From: Sawood Alam Date: Fri, 27 Oct 2017 17:02:56 -0400 Subject: [PATCH 2/6] Adding Docker related instructions for development --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e83844..97206a1 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,8 @@ If you get an error about a port "address already in use", you can change the `P Barring any changes, you may now visit a JSON endpoint at: `http://localhost:8080/repositories` +**Note:** Provided `docker-compose.yml` file is optimized for the development environment. Necessary changes should be made in it for production. + ### Local System Install Running this project directly on your system requires: @@ -106,8 +108,11 @@ Barring any changes, you may now visit a JSON endpoint at: `http://localhost:808 Please follow the install instructions above! Inclusion of tests are appreciated! -For a list of all availabe helper commands, just type `make`. +For a list of all available helper commands, just type `make`. +For easier development workflow, the application runs behind [gin](https://github.com/codegangsta/gin) on port `3000`. +This allows live building and reloading of the server when Go files are modified. +If for any reason this is an undesired behavior, simply comment out `- "3000:3000"` and `command: gin -i -p 3000 -a $PORT` lines from the `docker-compose.yml` file. ## License & Copyright From 22dbf44b1ddb55d1d141d6f80d3801a621463fbf Mon Sep 17 00:00:00 2001 From: Sawood Alam Date: Fri, 27 Oct 2017 17:16:01 -0400 Subject: [PATCH 3/6] Improved inline comments --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index f3f0f12..3757016 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,10 +15,10 @@ WORKDIR /go/src/github.com/datatogether/coverage # Run tests RUN go test -# Build the static api binary for production +# Build the static coverage api binary for production RUN CGO_ENABLED=0 GOOS=linux go install -a -installsuffix cgo -# Set binary as the default command +# Set the coverage binary as the default command CMD ["coverage"] # Start over from an Alpine Linux image as a base @@ -35,5 +35,5 @@ EXPOSE 8080 # Copy the binary from the dev stage into a location that is in PATH COPY --from=dev /go/bin/coverage /usr/local/bin/ -# Set binary as the default command +# Set the coverage binary as the default command CMD ["coverage"] From e61985bee34e3ba6620b01815ed10b523663f682 Mon Sep 17 00:00:00 2001 From: Sawood Alam Date: Fri, 27 Oct 2017 17:40:16 -0400 Subject: [PATCH 4/6] Changing port of Gin to minimize collision --- README.md | 4 ++-- docker-compose.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 97206a1..08bf1c9 100644 --- a/README.md +++ b/README.md @@ -110,9 +110,9 @@ Please follow the install instructions above! Inclusion of tests are appreciated For a list of all available helper commands, just type `make`. -For easier development workflow, the application runs behind [gin](https://github.com/codegangsta/gin) on port `3000`. +For easier development workflow, the application runs behind [gin](https://github.com/codegangsta/gin) on port `55555`. This allows live building and reloading of the server when Go files are modified. -If for any reason this is an undesired behavior, simply comment out `- "3000:3000"` and `command: gin -i -p 3000 -a $PORT` lines from the `docker-compose.yml` file. +If for any reason this is an undesired behavior, simply comment out `- "55555:55555"` and `command: gin -i -p 55555 -a $PORT` lines from the `docker-compose.yml` file. ## License & Copyright diff --git a/docker-compose.yml b/docker-compose.yml index 5979a84..d0c1e94 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,12 +10,12 @@ services: - ./sql:/sql ports: - "$PORT:$PORT" - - "3000:3000" + - "55555:55555" networks: - back-tier depends_on: - postgres - command: gin -i -p 3000 -a $PORT + command: gin -i -p 55555 -a $PORT postgres: image: "postgres:9.6-alpine" networks: From 98a491afd593555a79d48e1ad1210e4b7270ee67 Mon Sep 17 00:00:00 2001 From: Sawood Alam Date: Sun, 29 Oct 2017 21:31:58 -0400 Subject: [PATCH 5/6] Adding dockerignore, avoids env leakage, speeds up build, smaller image --- .dockerignore | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fa5d797 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +.git +.github +.gitignore +.circleci +.env +*.env +**/*.md +LICENSE +Dockerfile +docker-compose.yml From bbccece0c2833298c94a7746bc5d34246b057c85 Mon Sep 17 00:00:00 2001 From: Sawood Alam Date: Sun, 29 Oct 2017 21:37:55 -0400 Subject: [PATCH 6/6] Docker and Compose version requirement --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aa6ecd3..63da018 100644 --- a/README.md +++ b/README.md @@ -79,8 +79,8 @@ For people comfortable with Docker, or who are excited to learn about it, it can Running this project via Docker requires: - * [Docker](https://docs.docker.com/engine/installation/) - * [`docker-compose`](https://docs.docker.com/compose/install/) + * [Docker](https://docs.docker.com/engine/installation/) (17.06.0+) + * [Docker Compose](https://docs.docker.com/compose/install/) (1.6.0+) Running the project in a Docker container should be as simple as: