diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..de1e077 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM golang:1.20.5-alpine + +WORKDIR /app + +COPY go.mod go.sum ./ +COPY adapters ./adapters +COPY api ./api +COPY domain ./domain +COPY main ./main +COPY useCases ./useCases + +RUN go mod download +RUN go build -o startServer ./main + +CMD ["./startServer"] diff --git a/README.md b/README.md index 6b75963..7d72539 100644 --- a/README.md +++ b/README.md @@ -10,17 +10,22 @@ Don't forget to setup the [Environment variables](#environment-variables)! ### Use with Docker -TODO (or is it...) +#### Compose + +The easiest way to run the project is to use docker-compose. +You still need to set up the environment variables, but you can use the `.env` file for that. +Note that some supplementary variables are required for docker-compose to work, like `DOCKER_DB_FOLDER`. + +```bash +docker compose up --build -d +``` ### Build and run it yourself -#### Requirements - -- The project is developed with Go 1.20.5 - #### Build There are 2 scripts to build the project: + - `super_build.sh` - `super_build.bat` @@ -34,12 +39,13 @@ of course required, but not necessarily via the `.env` file. ### Environment variables -| Name | Type | Description | Comment | -|----------------------|--------|---------------------------------------|-------------------------------------------------------------------------------------------------------| -| ENVIRONMENT | string | The environment the API is running in | required, `development` or `production` | -| PORT | int | The port the API will use | required | -| CORS_ALLOWED_ORIGINS | string | The allowed origins for CORS | required, semicolon separated list | -| DB_FILE | string | The path to the sqlite db file | required, can be at the root but name still required (e.g. `./gohcms.db`) ; have to end up with `.db` | +| Name | Type | Description | Comment | +|----------------------|--------|-----------------------------------------|-------------------------------------------------------------------------------------------------------| +| ENVIRONMENT | string | The environment the API is running in | required, `development` or `production` | +| PORT | int | The port the API will use | required | +| CORS_ALLOWED_ORIGINS | string | The allowed origins for CORS | required, semicolon separated list | +| DB_FILE | string | The path to the sqlite db file | required, can be at the root but name still required (e.g. `./gohcms.db`) ; have to end up with `.db` | +| DOCKER_DB_FOLDER | string | The path to the sqlite db file's folder | required with docker, this will basically be the host machine folder that contains the sqlite db file | ## API Usage diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..7c75abe --- /dev/null +++ b/compose.yml @@ -0,0 +1,12 @@ +services: + api: + build: . + ports: + - "${PORT}:8080" + volumes: + - ${DOCKER_DB_FOLDER}:/app/db/ + environment: + - ENVIRONMENT=${ENVIRONMENT} + - PORT=8080 + - CORS_ALLOWED_ORIGINS=${CORS_ALLOWED_ORIGINS} + - DB_FILE=/app/db/gohcms.db