diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 943cd71..f58b8af 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -47,12 +47,36 @@ docker-build-prod-latest: --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 \ --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 \ --push \ --tag $CI_REGISTRY_IMAGE:latest \ . only: - main +docker-build-prod-tagged: + image: ezkrg/buildx + stage: build + services: + - docker:dind + before_script: + - docker buildx create --use + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY + script: + - | + docker buildx build \ + --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 \ + --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 \ + --push \ + --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG \ + . + only: + - tags + except: + - branches + docker-build-dry-run: image: docker:latest stage: build diff --git a/Dockerfile b/Dockerfile index 2e8f08b..7996d39 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,9 +4,11 @@ RUN apk add --no-cache git make build-base ARG CI_COMMIT_BRANCH ARG CI_COMMIT_SHORT_SHA +ARG CI_COMMIT_TAG ENV CI_COMMIT_BRANCH=$CI_COMMIT_BRANCH ENV CI_COMMIT_SHORT_SHA=$CI_COMMIT_SHORT_SHA +ENV CI_COMMIT_TAG=$CI_COMMIT_TAG ENV I_PACKAGE="git.ucode.space/Phil/goshorly/utils" ENV CGO_ENABLED=0 @@ -16,7 +18,7 @@ COPY . . RUN go get -d -v ./... -RUN go build -a -installsuffix cgo -ldflags=" -X $I_PACKAGE.GitCommitShort=$CI_COMMIT_SHORT_SHA -X $I_PACKAGE.GitBranch=$CI_COMMIT_BRANCH" -o app . +RUN go build -a -installsuffix cgo -ldflags=" -X $I_PACKAGE.CI_COMMIT_SHORT_SHA=$CI_COMMIT_SHORT_SHA -X $I_PACKAGE.CI_COMMIT_BRANCH=$CI_COMMIT_BRANCH -X $I_PACKAGE.CI_COMMIT_TAG=$CI_COMMIT_TAG" -o app . FROM scratch as production WORKDIR / diff --git a/routes/gethome.go b/routes/gethome.go index cdb3fe7..7000eeb 100644 --- a/routes/gethome.go +++ b/routes/gethome.go @@ -8,10 +8,12 @@ import ( func Gethome(c *fiber.Ctx) error { return c.Render("views/home", fiber.Map{ - "GitCommitShort": utils.GitCommitShort, - "GitBranch": utils.GitBranch, - "GitBuild": utils.GitBuild, - "TotalLinks": db.GetTotalLinks(), - "TotalViews": db.GetTotalViews(), + "CI_COMMIT_SHORT_SHA": utils.CI_COMMIT_SHORT_SHA, + "CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH, + "CI_COMMIT_TAG": utils.CI_COMMIT_TAG, + "CI_TAGGED": utils.CI_TAGGED, + "CI_BUILD": utils.CI_BUILD, + "TotalLinks": db.GetTotalLinks(), + "TotalViews": db.GetTotalViews(), }) } diff --git a/routes/posthome.go b/routes/posthome.go index 312f4e2..257cc00 100644 --- a/routes/posthome.go +++ b/routes/posthome.go @@ -28,12 +28,14 @@ func Posthome(c *fiber.Ctx) error { } return c.Status(500).Render("views/home", fiber.Map{ - "ERR": "Parsing Error", - "GitCommitShort": utils.GitCommitShort, - "GitBranch": utils.GitBranch, - "GitBuild": utils.GitBuild, - "TotalLinks": db.GetTotalLinks(), - "TotalViews": db.GetTotalViews(), + "ERR": "Parsing Error", + "CI_COMMIT_SHORT_SHA": utils.CI_COMMIT_SHORT_SHA, + "CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH, + "CI_COMMIT_TAG": utils.CI_COMMIT_TAG, + "CI_TAGGED": utils.CI_TAGGED, + "CI_BUILD": utils.CI_BUILD, + "TotalLinks": db.GetTotalLinks(), + "TotalViews": db.GetTotalViews(), }) } @@ -47,12 +49,14 @@ func Posthome(c *fiber.Ctx) error { } return c.Status(424).Render("views/home", fiber.Map{ - "ERR": "Invalid URL, please check and try again.", - "GitCommitShort": utils.GitCommitShort, - "GitBranch": utils.GitBranch, - "GitBuild": utils.GitBuild, - "TotalLinks": db.GetTotalLinks(), - "TotalViews": db.GetTotalViews(), + "ERR": "Invalid URL, please check and try again.", + "CI_COMMIT_SHORT_SHA": utils.CI_COMMIT_SHORT_SHA, + "CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH, + "CI_COMMIT_TAG": utils.CI_COMMIT_TAG, + "CI_TAGGED": utils.CI_TAGGED, + "CI_BUILD": utils.CI_BUILD, + "TotalLinks": db.GetTotalLinks(), + "TotalViews": db.GetTotalViews(), }) } @@ -68,12 +72,14 @@ func Posthome(c *fiber.Ctx) error { } return c.Status(500).Render("views/home", fiber.Map{ - "ERR": err.Error(), - "GitCommitShort": utils.GitCommitShort, - "GitBranch": utils.GitBranch, - "GitBuild": utils.GitBuild, - "TotalLinks": db.GetTotalLinks(), - "TotalViews": db.GetTotalViews(), + "ERR": err.Error(), + "CI_COMMIT_SHORT_SHA": utils.CI_COMMIT_SHORT_SHA, + "CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH, + "CI_COMMIT_TAG": utils.CI_COMMIT_TAG, + "CI_TAGGED": utils.CI_TAGGED, + "CI_BUILD": utils.CI_BUILD, + "TotalLinks": db.GetTotalLinks(), + "TotalViews": db.GetTotalViews(), }) } @@ -88,12 +94,14 @@ func Posthome(c *fiber.Ctx) error { } return c.Status(500).Render("views/home", fiber.Map{ - "ERR": err.Error(), - "GitCommitShort": utils.GitCommitShort, - "GitBranch": utils.GitBranch, - "GitBuild": utils.GitBuild, - "TotalLinks": db.GetTotalLinks(), - "TotalViews": db.GetTotalViews(), + "ERR": err.Error(), + "CI_COMMIT_SHORT_SHA": utils.CI_COMMIT_SHORT_SHA, + "CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH, + "CI_COMMIT_TAG": utils.CI_COMMIT_TAG, + "CI_TAGGED": utils.CI_TAGGED, + "CI_BUILD": utils.CI_BUILD, + "TotalLinks": db.GetTotalLinks(), + "TotalViews": db.GetTotalViews(), }) } @@ -114,11 +122,13 @@ func Posthome(c *fiber.Ctx) error { } return c.Status(201).Render("views/home", fiber.Map{ - "URL": fURL, - "GitCommitShort": utils.GitCommitShort, - "GitBranch": utils.GitBranch, - "GitBuild": utils.GitBuild, - "TotalLinks": db.GetTotalLinks(), - "TotalViews": db.GetTotalViews(), + "URL": fURL, + "CI_COMMIT_SHORT_SHA": utils.CI_COMMIT_SHORT_SHA, + "CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH, + "CI_COMMIT_TAG": utils.CI_COMMIT_TAG, + "CI_TAGGED": utils.CI_TAGGED, + "CI_BUILD": utils.CI_BUILD, + "TotalLinks": db.GetTotalLinks(), + "TotalViews": db.GetTotalViews(), }) } diff --git a/utils/build-vars.go b/utils/build-vars.go index 9a34c06..4789bd2 100644 --- a/utils/build-vars.go +++ b/utils/build-vars.go @@ -1,15 +1,22 @@ package utils var ( - GitCommitShort string - GitBranch string - GitBuild bool + CI_COMMIT_SHORT_SHA string + CI_COMMIT_BRANCH string + CI_COMMIT_TAG string + CI_TAGGED bool + CI_BUILD bool ) func Init_build_vars() { - if GitCommitShort == "" && GitBranch == "" { - GitBuild = false + if CI_COMMIT_SHORT_SHA == "" && CI_COMMIT_BRANCH == "" { + CI_BUILD = false } else { - GitBuild = true + CI_BUILD = true + } + if CI_COMMIT_TAG == "" { + CI_TAGGED = false + } else { + CI_TAGGED = true } } diff --git a/utils/limiter.go b/utils/limiter.go index f4f003a..7762e99 100644 --- a/utils/limiter.go +++ b/utils/limiter.go @@ -12,10 +12,10 @@ var ConfigLimiter limiter.Config = limiter.Config{ Expiration: 60 * time.Second, LimitReached: func(c *fiber.Ctx) error { return c.Render("views/home", fiber.Map{ - "ERR": "You have reached the limit of requests! Please check back later. (1 minute)", - "GitCommitShort": GitCommitShort, - "GitBranch": GitBranch, - "GitBuild": GitBuild, + "ERR": "You have reached the limit of requests! Please check back later. (1 minute)", + "CI_COMMIT_SHORT_SHA": CI_COMMIT_SHORT_SHA, + "CI_COMMIT_BRANCH": CI_COMMIT_BRANCH, + "CI_BUILD": CI_BUILD, }) }, } diff --git a/views/home.html b/views/home.html index a1307f2..9dedc22 100644 --- a/views/home.html +++ b/views/home.html @@ -78,8 +78,12 @@