From 8c0b7b322fbfc0b4076cfb54e6364102af29ff02 Mon Sep 17 00:00:00 2001 From: lyx0 <66651385+lyx0@users.noreply.github.com> Date: Sun, 3 Dec 2023 20:50:38 +0100 Subject: [PATCH] lidl dockerize --- .gitignore | 4 +++- Dockerfile | 20 ++++++++++++++++++++ Makefile | 6 ++++++ cmd/nourybot/main.go | 2 +- docker-compose.yml | 20 ++++++++++++++++++++ 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore index 942fdf4..45aa706 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,6 @@ NourybotApi NourybotApi.out nourybot-api Nourybot-Web -nourybot-web \ No newline at end of file +nourybot-web +nourybot + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..645887d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +# Start from golang base image +FROM golang:alpine + +RUN apk add --no-cache make +# Setup folders +RUN mkdir /app +WORKDIR /app + +# Copy the source from the current directory to the working Directory inside the container +COPY . . +COPY .env . + +# Download all the dependencies +RUN go get -d -v ./... + +# Build the Go app +RUN go build ./cmd/nourybot + +# Run the executable +CMD [ "./nourybot", "env='prod'" ] diff --git a/Makefile b/Makefile index 59ff8d5..cf14f1f 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,12 @@ jqprod: mv cmd/nourybot/${BINARY_NAME} ./bin/${BINARY_NAME} ./bin/${BINARY_NAME} -env="prod" | jq +build: + cd cmd/nourybot && go build -o ${BINARY_NAME} + mv cmd/nourybot/${BINARY_NAME} ./bin/${BINARY_NAME} + +run: + ./bin/${BINARY_NAME} -env="prod" prod: cd cmd/nourybot && go build -o ${BINARY_NAME} diff --git a/cmd/nourybot/main.go b/cmd/nourybot/main.go index 7d80430..6217c24 100644 --- a/cmd/nourybot/main.go +++ b/cmd/nourybot/main.go @@ -80,7 +80,7 @@ func main() { switch envFlag { case "dev": - cfg.db.dsn = os.Getenv("LOCAL_DSN") + cfg.db.dsn = os.Getenv("REMOTE_DSN") case "prod": cfg.db.dsn = os.Getenv("REMOTE_DSN") } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..612ff91 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +version: "3.7" +services: + database: + image: postgres + restart: always + env_file: + - .env + ports: + - "127.0.0.1:55432:5432" + volumes: + - data:/var/lib/postgresql/data + nourybot: + build: + context: . + dockerfile: Dockerfile + env_file: .env + depends_on: + - database +volumes: + data: \ No newline at end of file