Merge branch 'feature-ci-tag-refractor' into 'main'

Refractor code & adding ci tagged build

See merge request Phil/goshorly!13
This commit is contained in:
Phil 2022-01-11 12:05:07 +01:00
commit 510e7dad83
7 changed files with 97 additions and 48 deletions

View file

@ -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

View file

@ -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 /

View file

@ -8,9 +8,11 @@ import (
func Gethome(c *fiber.Ctx) error {
return c.Render("views/home", fiber.Map{
"GitCommitShort": utils.GitCommitShort,
"GitBranch": utils.GitBranch,
"GitBuild": utils.GitBuild,
"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(),
})

View file

@ -29,9 +29,11 @@ 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,
"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(),
})
@ -48,9 +50,11 @@ 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,
"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(),
})
@ -69,9 +73,11 @@ 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,
"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(),
})
@ -89,9 +95,11 @@ 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,
"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(),
})
@ -115,9 +123,11 @@ 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,
"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(),
})

View file

@ -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
}
}

View file

@ -13,9 +13,9 @@ var ConfigLimiter limiter.Config = limiter.Config{
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,
"CI_COMMIT_SHORT_SHA": CI_COMMIT_SHORT_SHA,
"CI_COMMIT_BRANCH": CI_COMMIT_BRANCH,
"CI_BUILD": CI_BUILD,
})
},
}

View file

@ -78,8 +78,12 @@
<center>
Made with <a href="https://git.ucode.space/Phil/goshorly"><i class="fas fa-code-branch"></i>
Phil/goshorly</a>
{{ if .GitBuild }}
| {{ .GitCommitShort }}/{{ .GitBranch }}
{{ if .CI_BUILD }}
{{ if .CI_COMMIT_TAG }}
| {{ .CI_COMMIT_TAG }}
{{ else }}
| {{ .CI_COMMIT_SHORT_SHA }}/{{ .CI_COMMIT_BRANCH }}
{{ end }}
{{ end }}
</center>
</footer>