From ede08baf22c8dab8f923800e97e162051ee6e418 Mon Sep 17 00:00:00 2001 From: David Lick Date: Tue, 26 May 2020 21:31:22 -0400 Subject: [PATCH] update local environment to build the bookish-api --- README.md | 28 +++------------------------- bookish-server/Dockerfile | 9 +++++++++ docker-compose.yml | 16 +++++++++++++++- 3 files changed, 27 insertions(+), 26 deletions(-) create mode 100644 bookish-server/Dockerfile diff --git a/README.md b/README.md index 633760b..c1f1c33 100644 --- a/README.md +++ b/README.md @@ -4,35 +4,13 @@ bookish is a customer relationship model for library systems. It keeps track of ## Prerequisites - You will need [Docker Desktop](https://docs.docker.com/desktop/) installed. -- You will need [Golang](https://golang.org/doc/install) installed. ## Getting Started -To run bookish locally you can use the docker-compose in the root directory to spin up the local environment: + +To run bookish locally first set the `BOOKSHOST` environment variable in `./docker-compose.yml` to the Books API hostname. You can then use the docker-compose from the root directory to spin up the local environment: ``` docker-compose up -d ``` -This will start a local MySQL container on port `3306` using the `root` user and password `123pass`. A volume will be mounted that holds spin up SQL scripts that will prepare the database for you. - -You will also need to add the following `.env` file to the `bookish-server/cmd/api` folder: - -``` -export APIPORT=3000 -export LOGLEVEL=Debug -export DBHOST=localhost -export DBUSER=root -export DBPASS=123pass -export DBPORT=3306 -export BOOKSHOST= -``` - -## Installing - -Before running the server call `go mod tidy` from the `bookish/bookish-server` directory to install any dependencies. - -## Testing - -To run unit tests for `bookish-server` run `go test ./...` from the `bookish/bookish-server` directory. - -## Usage +This will start a local MySQL container on port `3306` using the `root` user and password `123pass`. A volume will be mounted that holds spin up SQL scripts that will prepare the database for you.ish-server` directory. \ No newline at end of file diff --git a/bookish-server/Dockerfile b/bookish-server/Dockerfile new file mode 100644 index 0000000..3bb37e4 --- /dev/null +++ b/bookish-server/Dockerfile @@ -0,0 +1,9 @@ +FROM golang:latest + +WORKDIR /go/src/bookish +COPY . . + +RUN go get -d -v ./... +RUN go install -v ./... + +CMD ["api"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 6f521d5..83f44bb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,20 @@ -version: "3.1" +version: "3.8" services: + api: + build: ./bookish-server + depends_on: + - db + ports: + - 3001:3001 + environment: + - APIPORT=3001 + - LOGLEVEL=Debug + - DBHOST=db + - DBUSER=root + - DBPASS=123pass + - DBPORT=3306 + - BOOKSHOST=< db: image: mysql ports: