From c6713e1e06e9b4bd3b317f899463df0c78fd28eb Mon Sep 17 00:00:00 2001 From: Gabe Date: Tue, 5 Apr 2022 13:49:35 -0700 Subject: [PATCH] Add docker compose and running instructions (#22) * update to ssi sdk * update readme * config, did router test * health and readiness api tests * did http test * pretty picture; readme update * add docker-compose --- README.md | 21 +++++++++++++++++++-- build/Dockerfile | 20 ++++++++++++++++++++ build/docker-compose.yml | 8 ++++++++ magefile.go | 5 +++++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 build/Dockerfile create mode 100644 build/docker-compose.yml diff --git a/README.md b/README.md index 999c1ba78..5bdf79511 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,25 @@ revoking, exchanging, validating, verifying credentials in varying degrees of co ## Deployment -The service will be packaged as a [Docker container](https://www.docker.com/), runnable in a wide variety of -environments. It may be expanded to support multiple protocols and transports besides HTTP/REST. +The service is packaged as a [Docker container](https://www.docker.com/), runnable in a wide variety of +environments. [Docker Compose](https://docs.docker.com/compose/) is used for simplification and orchestration. To run +the service, you can use the following command, which will start the service on port `8080`: + +```shell +mage run +``` + +Or, you can run docker-compose yourself: + +```shell +cd build && docker-compose up +``` + +You should then be able to send requests as follows: +```shell + ~ curl localhost:8080/health +{"status":"OK"} +``` ## What's Supported? diff --git a/build/Dockerfile b/build/Dockerfile new file mode 100644 index 000000000..66275bc3f --- /dev/null +++ b/build/Dockerfile @@ -0,0 +1,20 @@ +FROM golang:1.17-alpine + +# Create directory for our app inside the container +WORKDIR /app + +# Prepare dependencies +COPY go.mod ./ +COPY go.sum ./ +RUN go mod download + +# Copy code /to the container image. +COPY . ./ + +# Build the binary and call it "docker-ssi-service" +RUN ls -alt +RUN go build -tags jwx_es256k -o /docker-ssi-service ./cmd + +EXPOSE 3000 + +CMD [ "/docker-ssi-service" ] \ No newline at end of file diff --git a/build/docker-compose.yml b/build/docker-compose.yml new file mode 100644 index 000000000..82f9b032a --- /dev/null +++ b/build/docker-compose.yml @@ -0,0 +1,8 @@ +version: "3.98" +services: + web: + build: + context: ../ + dockerfile: build/Dockerfile + ports: + - "8080:3000" \ No newline at end of file diff --git a/magefile.go b/magefile.go index 1876db8c6..f5c00a82e 100644 --- a/magefile.go +++ b/magefile.go @@ -36,6 +36,11 @@ func Clean() { os.RemoveAll("bin") } +// Run the service via docker-compose +func Run() error { + return sh.Run("docker-compose", "--project-directory", "build", "up") +} + // Test runs unit tests without coverage. // The mage `-v` option will trigger a verbose output of the test func Test() error {