From b5a9a3e669769eee9e2867264555a0f96ddf0fe6 Mon Sep 17 00:00:00 2001 From: Ada Date: Wed, 14 Feb 2024 18:57:27 +0100 Subject: [PATCH 1/2] :wrench: Supresss automatic .env load Automatic load of .env is a problem for Docker and not really usefull in other context --- go.mod | 5 +---- go.sum | 2 -- internal/config/config.go | 7 ------- 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 042b6ec..0e58b75 100644 --- a/go.mod +++ b/go.mod @@ -2,10 +2,7 @@ module git.gnous.eu/gnouseu/plakken go 1.22 -require ( - github.com/joho/godotenv v1.5.1 - github.com/redis/go-redis/v9 v9.4.0 -) +require github.com/redis/go-redis/v9 v9.4.0 require ( github.com/cespare/xxhash/v2 v2.2.0 // indirect diff --git a/go.sum b/go.sum index 6c245cb..85f5563 100644 --- a/go.sum +++ b/go.sum @@ -6,7 +6,5 @@ github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= -github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= -github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/redis/go-redis/v9 v9.4.0 h1:Yzoz33UZw9I/mFhx4MNrB6Fk+XHO1VukNcCa1+lwyKk= github.com/redis/go-redis/v9 v9.4.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M= diff --git a/internal/config/config.go b/internal/config/config.go index 2576b54..373f03e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -4,8 +4,6 @@ import ( "log" "os" "strconv" - - "github.com/joho/godotenv" ) // InitConfig Structure for program initialisation @@ -20,11 +18,6 @@ type InitConfig struct { // GetConfig Initialise configuration form .env func GetConfig() InitConfig { - err := godotenv.Load() - if err != nil { - log.Fatalf("Error loading .env file: %v", err) - } - listenAddress := os.Getenv("PLAKKEN_LISTEN") redisAddress := os.Getenv("PLAKKEN_REDIS_ADDRESS") db := os.Getenv("PLAKKEN_REDIS_DB") From eaaf09c97878c2ad4245fa0d55df1b771e65d83c Mon Sep 17 00:00:00 2001 From: Ada Date: Wed, 14 Feb 2024 19:00:32 +0100 Subject: [PATCH 2/2] :construction_worker: Add docker support and CI related stuff --- .woodpecker/build.yaml | 32 ++++++++++++++++++++++++++++++ docker/Dockerfile | 28 ++++++++++++++++++++++++++ docker/docker-compose.dev.yaml | 31 +++++++++++++++++++++++++++++ docker/docker-compose.yaml | 36 ++++++++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 .woodpecker/build.yaml create mode 100644 docker/Dockerfile create mode 100644 docker/docker-compose.dev.yaml create mode 100644 docker/docker-compose.yaml diff --git a/.woodpecker/build.yaml b/.woodpecker/build.yaml new file mode 100644 index 0000000..88083af --- /dev/null +++ b/.woodpecker/build.yaml @@ -0,0 +1,32 @@ +steps: + - name: publish_image + image: woodpeckerci/plugin-docker-buildx + settings: + repo: git.gnous.eu/${CI_REPO_OWNER}/plakken + dockerfile: docker/Dockerfile + platforms: linux/amd64,linux/arm64/v8,linux/arm + registry: https://git.gnous.eu + tag: ${CI_COMMIT} + username: + from_secret: docker_username + password: + from_secret: docker_password + when: + branch: ${CI_REPO_DEFAULT_BRANCH} + event: push + - name: publish_image_tag + image: woodpeckerci/plugin-docker-buildx + settings: + repo: git.gnous.eu/${CI_REPO_OWNER}/plakken + dockerfile: docker/Dockerfile + platforms: linux/amd64,linux/arm64/v8,linux/arm + registry: https://git.gnous.eu + tags: + - ${CI_COMMIT_TAG##v} # Remove v from tag + - stable + username: + from_secret: docker_username + password: + from_secret: docker_password + when: + event: tag diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..f50175c --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,28 @@ +# Build +FROM golang:1.22 AS build +LABEL authors="gnousEU" + +WORKDIR /build + +COPY go.mod go.sum ./ +RUN go mod download + +COPY main.go ./ +COPY internal/ ./internal +COPY static/ ./static +COPY templates/ ./templates + +RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-w -s" # Enable static binary, target Linux, remove debug information and strip binary + +# Copy to our image +FROM gcr.io/distroless/static-debian12:nonroot + +WORKDIR /app + +COPY --from=build /build/plakken ./ + +ENV PLAKKEN_LISTEN ":3000" + +EXPOSE 3000/tcp + +ENTRYPOINT ["/app/plakken"] diff --git a/docker/docker-compose.dev.yaml b/docker/docker-compose.dev.yaml new file mode 100644 index 0000000..8ec1e6e --- /dev/null +++ b/docker/docker-compose.dev.yaml @@ -0,0 +1,31 @@ +version: "3" + +networks: + plakken: + external: false + +services: + server: + build: + context: ../ + dockerfile: docker/Dockerfile + restart: always + container_name: plakken + networks: + - plakken + ports: + - "3000:3000" + environment: + - PLAKKEN_REDIS_ADDRESS=redis:6379 + - POSTGRES_PASSWORD=gitea + - PLAKKEN_REDIS_DB=0 + - PLAKKEN_URL_LENGTH=5 + depends_on: + - redis + redis: + image: redis:7-alpine + restart: always + healthcheck: + test: [ "CMD", "redis-cli", "ping" ] + networks: + - plakken diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml new file mode 100644 index 0000000..1dc30b0 --- /dev/null +++ b/docker/docker-compose.yaml @@ -0,0 +1,36 @@ +version: "3" + +networks: + plakken: + external: false + +volumes: + redis: + driver: local + +services: + server: + image: git.gnous.eu/gnouseu/plakken:latest + restart: always + container_name: plakken + read_only: true + networks: + - plakken + ports: + - "3000:3000" + environment: + - PLAKKEN_REDIS_ADDRESS=redis:6379 + - POSTGRES_PASSWORD=gitea + - PLAKKEN_REDIS_DB=0 + - PLAKKEN_URL_LENGTH=5 + depends_on: + - redis + redis: + image: redis:7-alpine + restart: always + healthcheck: + test: [ "CMD", "redis-cli", "ping" ] + networks: + - plakken + volumes: + - redis:/data