From 5ab9d9d0e00a06f2ca98fa6c4805c0b1302d447a Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Fri, 3 May 2024 22:40:45 +0200 Subject: [PATCH] Add docker and compose --- .env.example | 9 +++++++++ .gitignore | 1 + api/Dockerfile | 9 +++++++++ api/Dockerfile.dev | 6 ++++++ docker-compose.dev.yml | 29 +++++++++++++++++++++++++++++ docker-compose.yml | 25 +++++++++++++++++++++++++ 6 files changed, 79 insertions(+) create mode 100644 .env.example create mode 100644 .gitignore create mode 100644 api/Dockerfile create mode 100644 api/Dockerfile.dev create mode 100644 docker-compose.dev.yml create mode 100644 docker-compose.yml diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..f14e063 --- /dev/null +++ b/.env.example @@ -0,0 +1,9 @@ +# vi: ft=sh +# shellcheck disable=SC2034 + +# Database things +POSTGRES_USER=vex +POSTGRES_PASSWORD=pass +POSTGRES_DB=vex_db +POSTGRES_SERVER=postgres +POSTGRES_PORT=5432 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/api/Dockerfile b/api/Dockerfile new file mode 100644 index 0000000..e106ee3 --- /dev/null +++ b/api/Dockerfile @@ -0,0 +1,9 @@ +FROM golang:1.22-alpine +WORKDIR /app +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +RUN go build -o ./vex + +EXPOSE 1597 +CMD ./vex diff --git a/api/Dockerfile.dev b/api/Dockerfile.dev new file mode 100644 index 0000000..f6324c7 --- /dev/null +++ b/api/Dockerfile.dev @@ -0,0 +1,6 @@ +FROM golang:1.22-alpine +RUN go install github.com/bokwoon95/wgo@latest +WORKDIR /app + +EXPOSE 1597 +CMD wgo run . diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..bccddc8 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,29 @@ +services: + api: + build: + context: ./api + dockerfile: Dockerfile.dev + restart: on-failure + volumes: + - ./api:/app + env_file: + - ./.env + depends_on: + postgres: + condition: service_healthy + + postgres: + image: postgres:15 + restart: on-failure + env_file: + - ./.env + volumes: + - db:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"] + interval: 5s + timeout: 5s + retries: 5 + +volumes: + db: diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..224bc06 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +services: + api: + build: ./api + restart: on-failure + env_file: + - ./.env + depends_on: + postgres: + condition: service_healthy + + postgres: + image: postgres:15 + restart: on-failure + env_file: + - ./.env + volumes: + - db:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"] + interval: 5s + timeout: 5s + retries: 5 + +volumes: + db: