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 diff --git a/Dockerfile b/Dockerfile index b1a435e..3757016 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 coverage 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 the coverage binary as the default command +CMD ["coverage"] # Start over from an Alpine Linux image as a base # to create a minumal production image @@ -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"] diff --git a/README.md b/README.md index d3c3fef..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: @@ -93,6 +93,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: @@ -121,4 +123,8 @@ 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 `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 `- "55555:55555"` and `command: gin -i -p 55555 -a $PORT` lines from the `docker-compose.yml` file. diff --git a/docker-compose.yml b/docker-compose.yml index 5fe0b8f..d0c1e94 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" + - "55555:55555" 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 55555 -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