From 9024ccc11e6acdd0e6c9e3f5d9f3944c0541445c Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Fri, 16 Jun 2023 13:17:31 +0300 Subject: [PATCH] feat: docker compose deployment --- Dockerfile | 25 +++++++++++++++++++++++++ dev.elv | 39 +++++++++++++++++++++++++++++---------- docker-compose.yaml | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 10 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yaml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..29a340c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +# builder +FROM golang:1.20.1-alpine AS builder + +WORKDIR /usr/src/app + +COPY go.mod go.sum ./ +RUN go mod download && go mod verify + +COPY . . + +RUN CGO_ENABLED=0 GOOS=linux go build -v -o /tixe ./tixe.go + +# tester +FROM builder AS tester +RUN go test -v ./... + +# release +FROM alpine:3.18 AS release + +COPY --from=builder /tixe /tixe +ADD ./static /static + +EXPOSE 8080 + +ENTRYPOINT ["/tixe"] diff --git a/dev.elv b/dev.elv index 6c0240a..6e17505 100755 --- a/dev.elv +++ b/dev.elv @@ -2,25 +2,44 @@ fn run { clear - go run tixe.go + docker compose up --build } -fn build { +fn clean { clear - go build + docker compose down + docker volume rm tixe_tixedb_data +} + +fn docker_menu { + var input + while (not-eq $input "b") { + echo "[R]un, [C]lean, [B]ack" + set input = (sh -c 'read -n1 && echo $REPLY' | take 1) + + if (eq $input "r") { + run + } elif (eq $input "c") { + clean + } + } +} + +fn tailwind_watch { + clear + tailwindcss -i input.css -o ./static/styles.css --watch } var input while (not-eq $input "q") { clear + echo "[D]ev Deploy, [T]ailwind Watch, [Q]uit" - echo "[R]un, [B]uild, [Q]uit" - - set input = (read-line) + set input = (sh -c 'read -n1 && echo $REPLY' | take 1) - if (eq $input "r") { - run - } elif (eq $input "b") { - build + if (eq $input "d") { + docker_menu + } elif (eq $input "t") { + tailwind_watch } } diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..cd97064 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,45 @@ +version: "3.8" + +networks: + internal: + external: false + +volumes: + tixedb_data: + driver: local + +services: + tixedb: + image: postgres:15-alpine + container_name: tixedb + restart: always + networks: + - internal + volumes: + - tixedb_data:/var/lib/postgresql/data + environment: + POSTGRES_USER: tixe + POSTGRES_PASSWORD: tixe + POSTGRES_DB: tixe + + tixe: + build: . + image: tixe + container_name: tixe + restart: always + networks: + - internal + ports: + - 8080:8080 + environment: + TZ: Europe/Helsinki + GIN_MODE: release # or "debug" for debug logs + TIXE_PSQL_HOST: tixedb + TIXE_PSQL_PORT: 5432 + TIXE_PSQL_USER: tixe + TIXE_PSQL_PASSWORD: tixe + TIXE_PSQL_DB: tixe + TIXE_OIDC_GITHUB: false + TIXE_OIDC_CUSTOM: true + depends_on: + - tixedb -- 2.44.1