From 469d94fb9811375f2a49d65e7a472ae2437a83c6 Mon Sep 17 00:00:00 2001 From: Phil Date: Sun, 23 Jan 2022 22:16:01 +0100 Subject: [PATCH 1/4] speed up docker-buildkit --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5c9b455..4eecae5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -161,7 +161,8 @@ docker-build-prod-tagged: script: - | docker buildx build \ - --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 \ + --platform linux/amd64,linux/arm64 \ + --no-cache \ --build-arg CI_COMMIT_BRANCH=$CI_COMMIT_BRANCH \ --build-arg CI_COMMIT_SHORT_SHA=$CI_COMMIT_SHORT_SHA \ --build-arg CI_COMMIT_TAG=$CI_COMMIT_TAG \ From 0af8219322bb892e35db17a36de2212fd381d016 Mon Sep 17 00:00:00 2001 From: Phil Date: Sun, 23 Jan 2022 22:21:49 +0100 Subject: [PATCH 2/4] Changed README --- README.md | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bef8d5b..1ebca30 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,19 @@ ![](https://git.ucode.space/Phil/goshorly/badges/main/pipeline.svg) # goshorly -An easy self-hosted Link shortener in Golang with Redis <3 - -[Live-Demo](https://gly.one) | Stable Build - +An easy self-hosted Link shortener in Golang with Redis <3 [Live-Demo](https://gly.one) +--- +## Supported architectures +### Docker +- amd64, arm64 +- other versions can be build manually (via docker build) +## Binary Build +- linux (amd64,arm64) +- darwin (amd64,arm64) +- windows (amd64) +- other versions can be build manually (via go build) +--- **WARNING:** - goshorly is in an early stage, it is not an Final Version! (Pre-Release Status v0.1.X) @@ -14,6 +22,8 @@ If you have an feature request, please do not hesitate to open an issue or merge Available Docker tags: - https://git.ucode.space/Phil/goshorly/container_registry/1 + +## Install with Docker Installation with Docker-Compose (with no reverse proxy / own proxy): ```bash mkdir goshorly @@ -32,3 +42,6 @@ mv docker-compose-proxy.yml docker-compose.yml nano docker-compose.yml # Change the command line on caddy to your domain & environment variables to your needs docker-compose up -d ``` + +## Install with Binary version +- WIP \ No newline at end of file From 5307f078c029d39b85f33a474ae38a9b2290ae2e Mon Sep 17 00:00:00 2001 From: Phil Date: Sun, 23 Jan 2022 22:24:19 +0100 Subject: [PATCH 3/4] Changed golang:latest to golang:alpine in CI --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4eecae5..5e1645a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,7 +8,7 @@ stages: - build-docker check-format: - image: golang:latest + image: golang:alpine stage: test before_script: - mkdir -p $GOPATH/src/$(dirname $REPO_NAME) @@ -22,7 +22,7 @@ check-format: - merge_requests check-gosec: - image: golang:latest + image: golang:alpine before_script: - mkdir -p $GOPATH/src/$(dirname $REPO_NAME) - ln -svf $CI_PROJECT_DIR $GOPATH/src/$REPO_NAME From 03093a8b1bf611750159e4fa9045ec3839177a44 Mon Sep 17 00:00:00 2001 From: Phil Date: Tue, 25 Jan 2022 17:25:23 +0100 Subject: [PATCH 4/4] Changed env layout + Start info --- db/connection.go | 7 ++++--- docker-compose-proxy.yml | 12 ++++++------ docker-compose.yml | 12 ++++++------ main.go | 1 + utils/build-vars.go | 18 ++++++++++++++++++ utils/env.go | 19 ++++++++++++++++--- 6 files changed, 51 insertions(+), 18 deletions(-) diff --git a/db/connection.go b/db/connection.go index 7541edd..e8c5cb2 100644 --- a/db/connection.go +++ b/db/connection.go @@ -4,15 +4,16 @@ import ( "context" "log" + "git.ucode.space/Phil/goshorly/utils" "github.com/go-redis/redis/v8" ) var ctx = context.Background() var Client *redis.Client = redis.NewClient(&redis.Options{ - Addr: "redis:6379", // use default Addr - Password: "", // no password set - DB: 0, // use default DB + Addr: utils.REDIS_URI, // use default Addr + Password: "", // no password set + DB: 0, // use default DB }) func Init_redis() { diff --git a/docker-compose-proxy.yml b/docker-compose-proxy.yml index 5d40e7e..e8b50da 100644 --- a/docker-compose-proxy.yml +++ b/docker-compose-proxy.yml @@ -4,12 +4,12 @@ services: # build: . # Only if you want to Build the image on your own Server! image: registry.ucode.space/phil/goshorly:latest environment: - - HOST=127.0.0.1 # Domain or IP-Adress - - PORT=3000 # The Port you want to use - - HTTPS=true # If you want to use HTTPS - - PROXY=true # If you want to use a Reverse Proxy - - REDIS_URI=redis # The Redis-URI (name of redis container OOTB) - - ENABLE_STATS=true # Enables the /stats public frontend + - HOST="127.0.0.1" # Domain or IP-Adress + - PORT="3000" # The Port you want to use + - HTTPS="true" # If you want to use HTTPS + - PROXY="true" # If you want to use a Reverse Proxy + - REDIS_URI="redis" # The Redis-URI (name of redis container OOTB) + - ENABLE_STATS="true" # Enables the /stats public frontend depends_on: - redis restart: always diff --git a/docker-compose.yml b/docker-compose.yml index 43e1757..60ed52c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,12 +4,12 @@ services: # build: . # Only if you want to Build the image on your own Server! image: registry.ucode.space/phil/goshorly:latest environment: - - HOST=127.0.0.1 # Domain or IP-Adress - - PORT=3000 # The Port you want to use - - HTTPS=false # If you want to use HTTPS - - PROXY=false # If you want to use a Reverse Proxy - - REDIS_URI=redis # The Redis-URI (name of redis container OOTB) - - ENABLE_STATS=true # Enables the /stats public frontend (Default: true) + - HOST="127.0.0.1" # Domain or IP-Adress + - PORT="3000" # The Port you want to use + - HTTPS="false" # If you want to use HTTPS + - PROXY="false" # If you want to use a Reverse Proxy + - REDIS_URI="redis" # The Redis-URI (name of redis container OOTB) + - ENABLE_STATS="true" # Enables the /stats public frontend (Default: true) ports: - "3000:3000" depends_on: diff --git a/main.go b/main.go index 57ce977..baea2b4 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ import ( var viewsfs embed.FS func main() { + utils.Print_Starting_Screen() utils.Init_env_vars() utils.Init_build_vars() diff --git a/utils/build-vars.go b/utils/build-vars.go index 4789bd2..de476e4 100644 --- a/utils/build-vars.go +++ b/utils/build-vars.go @@ -1,5 +1,10 @@ package utils +import ( + "fmt" + "time" +) + var ( CI_COMMIT_SHORT_SHA string CI_COMMIT_BRANCH string @@ -20,3 +25,16 @@ func Init_build_vars() { CI_TAGGED = true } } + +func Print_Starting_Screen() { + if CI_BUILD { + if CI_TAGGED { + fmt.Println("---- Starting goshorly " + CI_COMMIT_TAG + " ----") + } else { + fmt.Println("---- Starting goshorly " + CI_COMMIT_SHORT_SHA + " ----") + } + } else { + fmt.Println("---- Starting goshorly " + "unknown version" + " ----") + } + time.Sleep(1 * time.Second) +} diff --git a/utils/env.go b/utils/env.go index 4db8c5c..cfdc8b3 100644 --- a/utils/env.go +++ b/utils/env.go @@ -1,6 +1,7 @@ package utils import ( + "fmt" "log" "os" ) @@ -16,12 +17,14 @@ var ( ) func Init_env_vars() { + fmt.Println("-- Initializing environment variables... --") UHOST, err := os.LookupEnv("HOST") if !err { log.Fatal("HOST enviroment variable not found, please set it!") } HOST = UHOST + fmt.Println("HOST: ", HOST) UHTTPS, _ := os.LookupEnv("HTTPS") if UHTTPS != "true" { @@ -29,6 +32,7 @@ func Init_env_vars() { } else { HTTPS = "https" } + fmt.Println("Proto: ", HTTPS) UPROXY, _ := os.LookupEnv("PROXY") if UPROXY != "true" { @@ -36,6 +40,7 @@ func Init_env_vars() { } else { PROXY = true } + fmt.Println("Own reverse proxy: ", PROXY) UPORT, err := os.LookupEnv("PORT") if !err { @@ -43,11 +48,15 @@ func Init_env_vars() { } else { PORT = UPORT } + fmt.Println("Port: ", PORT) - UREDIS_URI, _ := os.LookupEnv("REDIS_URI") - if UREDIS_URI != "" { - REDIS_URI = "redis" + UREDIS_URI, err := os.LookupEnv("REDIS_URI") + if !err { + REDIS_URI = "redis:6379" + } else { + REDIS_URI = UREDIS_URI } + fmt.Println("Redis URI: ", REDIS_URI) UESTATS, _ := os.LookupEnv("ENABLE_STATS") if UESTATS != "false" { @@ -55,6 +64,7 @@ func Init_env_vars() { } else { ESTATS = "false" } + fmt.Println("Stats enabled: ", ESTATS) create_string() @@ -66,4 +76,7 @@ func create_string() { } else { URL = HTTPS + "://" + HOST + "/" } + + fmt.Println("URL: ", URL) + fmt.Println("-- Environment variables initialized! / Starting Webserver --") }