Refractor code & adding ci tagged build
This commit is contained in:
parent
066faed3e0
commit
5428ae09fb
7 changed files with 97 additions and 48 deletions
|
@ -47,12 +47,36 @@ docker-build-prod-latest:
|
||||||
--platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 \
|
--platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 \
|
||||||
--build-arg CI_COMMIT_BRANCH=$CI_COMMIT_BRANCH \
|
--build-arg CI_COMMIT_BRANCH=$CI_COMMIT_BRANCH \
|
||||||
--build-arg CI_COMMIT_SHORT_SHA=$CI_COMMIT_SHORT_SHA \
|
--build-arg CI_COMMIT_SHORT_SHA=$CI_COMMIT_SHORT_SHA \
|
||||||
|
--build-arg CI_COMMIT_TAG=$CI_COMMIT_TAG \
|
||||||
--push \
|
--push \
|
||||||
--tag $CI_REGISTRY_IMAGE:latest \
|
--tag $CI_REGISTRY_IMAGE:latest \
|
||||||
.
|
.
|
||||||
only:
|
only:
|
||||||
- main
|
- 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:
|
docker-build-dry-run:
|
||||||
image: docker:latest
|
image: docker:latest
|
||||||
stage: build
|
stage: build
|
||||||
|
|
|
@ -4,9 +4,11 @@ RUN apk add --no-cache git make build-base
|
||||||
|
|
||||||
ARG CI_COMMIT_BRANCH
|
ARG CI_COMMIT_BRANCH
|
||||||
ARG CI_COMMIT_SHORT_SHA
|
ARG CI_COMMIT_SHORT_SHA
|
||||||
|
ARG CI_COMMIT_TAG
|
||||||
|
|
||||||
ENV CI_COMMIT_BRANCH=$CI_COMMIT_BRANCH
|
ENV CI_COMMIT_BRANCH=$CI_COMMIT_BRANCH
|
||||||
ENV CI_COMMIT_SHORT_SHA=$CI_COMMIT_SHORT_SHA
|
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 I_PACKAGE="git.ucode.space/Phil/goshorly/utils"
|
||||||
ENV CGO_ENABLED=0
|
ENV CGO_ENABLED=0
|
||||||
|
@ -16,7 +18,7 @@ COPY . .
|
||||||
|
|
||||||
RUN go get -d -v ./...
|
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
|
FROM scratch as production
|
||||||
WORKDIR /
|
WORKDIR /
|
||||||
|
|
|
@ -8,9 +8,11 @@ import (
|
||||||
|
|
||||||
func Gethome(c *fiber.Ctx) error {
|
func Gethome(c *fiber.Ctx) error {
|
||||||
return c.Render("views/home", fiber.Map{
|
return c.Render("views/home", fiber.Map{
|
||||||
"GitCommitShort": utils.GitCommitShort,
|
"CI_COMMIT_SHORT_SHA": utils.CI_COMMIT_SHORT_SHA,
|
||||||
"GitBranch": utils.GitBranch,
|
"CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH,
|
||||||
"GitBuild": utils.GitBuild,
|
"CI_COMMIT_TAG": utils.CI_COMMIT_TAG,
|
||||||
|
"CI_TAGGED": utils.CI_TAGGED,
|
||||||
|
"CI_BUILD": utils.CI_BUILD,
|
||||||
"TotalLinks": db.GetTotalLinks(),
|
"TotalLinks": db.GetTotalLinks(),
|
||||||
"TotalViews": db.GetTotalViews(),
|
"TotalViews": db.GetTotalViews(),
|
||||||
})
|
})
|
||||||
|
|
|
@ -29,9 +29,11 @@ func Posthome(c *fiber.Ctx) error {
|
||||||
|
|
||||||
return c.Status(500).Render("views/home", fiber.Map{
|
return c.Status(500).Render("views/home", fiber.Map{
|
||||||
"ERR": "Parsing Error",
|
"ERR": "Parsing Error",
|
||||||
"GitCommitShort": utils.GitCommitShort,
|
"CI_COMMIT_SHORT_SHA": utils.CI_COMMIT_SHORT_SHA,
|
||||||
"GitBranch": utils.GitBranch,
|
"CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH,
|
||||||
"GitBuild": utils.GitBuild,
|
"CI_COMMIT_TAG": utils.CI_COMMIT_TAG,
|
||||||
|
"CI_TAGGED": utils.CI_TAGGED,
|
||||||
|
"CI_BUILD": utils.CI_BUILD,
|
||||||
"TotalLinks": db.GetTotalLinks(),
|
"TotalLinks": db.GetTotalLinks(),
|
||||||
"TotalViews": db.GetTotalViews(),
|
"TotalViews": db.GetTotalViews(),
|
||||||
})
|
})
|
||||||
|
@ -48,9 +50,11 @@ func Posthome(c *fiber.Ctx) error {
|
||||||
|
|
||||||
return c.Status(424).Render("views/home", fiber.Map{
|
return c.Status(424).Render("views/home", fiber.Map{
|
||||||
"ERR": "Invalid URL, please check and try again.",
|
"ERR": "Invalid URL, please check and try again.",
|
||||||
"GitCommitShort": utils.GitCommitShort,
|
"CI_COMMIT_SHORT_SHA": utils.CI_COMMIT_SHORT_SHA,
|
||||||
"GitBranch": utils.GitBranch,
|
"CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH,
|
||||||
"GitBuild": utils.GitBuild,
|
"CI_COMMIT_TAG": utils.CI_COMMIT_TAG,
|
||||||
|
"CI_TAGGED": utils.CI_TAGGED,
|
||||||
|
"CI_BUILD": utils.CI_BUILD,
|
||||||
"TotalLinks": db.GetTotalLinks(),
|
"TotalLinks": db.GetTotalLinks(),
|
||||||
"TotalViews": db.GetTotalViews(),
|
"TotalViews": db.GetTotalViews(),
|
||||||
})
|
})
|
||||||
|
@ -69,9 +73,11 @@ func Posthome(c *fiber.Ctx) error {
|
||||||
|
|
||||||
return c.Status(500).Render("views/home", fiber.Map{
|
return c.Status(500).Render("views/home", fiber.Map{
|
||||||
"ERR": err.Error(),
|
"ERR": err.Error(),
|
||||||
"GitCommitShort": utils.GitCommitShort,
|
"CI_COMMIT_SHORT_SHA": utils.CI_COMMIT_SHORT_SHA,
|
||||||
"GitBranch": utils.GitBranch,
|
"CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH,
|
||||||
"GitBuild": utils.GitBuild,
|
"CI_COMMIT_TAG": utils.CI_COMMIT_TAG,
|
||||||
|
"CI_TAGGED": utils.CI_TAGGED,
|
||||||
|
"CI_BUILD": utils.CI_BUILD,
|
||||||
"TotalLinks": db.GetTotalLinks(),
|
"TotalLinks": db.GetTotalLinks(),
|
||||||
"TotalViews": db.GetTotalViews(),
|
"TotalViews": db.GetTotalViews(),
|
||||||
})
|
})
|
||||||
|
@ -89,9 +95,11 @@ func Posthome(c *fiber.Ctx) error {
|
||||||
|
|
||||||
return c.Status(500).Render("views/home", fiber.Map{
|
return c.Status(500).Render("views/home", fiber.Map{
|
||||||
"ERR": err.Error(),
|
"ERR": err.Error(),
|
||||||
"GitCommitShort": utils.GitCommitShort,
|
"CI_COMMIT_SHORT_SHA": utils.CI_COMMIT_SHORT_SHA,
|
||||||
"GitBranch": utils.GitBranch,
|
"CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH,
|
||||||
"GitBuild": utils.GitBuild,
|
"CI_COMMIT_TAG": utils.CI_COMMIT_TAG,
|
||||||
|
"CI_TAGGED": utils.CI_TAGGED,
|
||||||
|
"CI_BUILD": utils.CI_BUILD,
|
||||||
"TotalLinks": db.GetTotalLinks(),
|
"TotalLinks": db.GetTotalLinks(),
|
||||||
"TotalViews": db.GetTotalViews(),
|
"TotalViews": db.GetTotalViews(),
|
||||||
})
|
})
|
||||||
|
@ -115,9 +123,11 @@ func Posthome(c *fiber.Ctx) error {
|
||||||
|
|
||||||
return c.Status(201).Render("views/home", fiber.Map{
|
return c.Status(201).Render("views/home", fiber.Map{
|
||||||
"URL": fURL,
|
"URL": fURL,
|
||||||
"GitCommitShort": utils.GitCommitShort,
|
"CI_COMMIT_SHORT_SHA": utils.CI_COMMIT_SHORT_SHA,
|
||||||
"GitBranch": utils.GitBranch,
|
"CI_COMMIT_BRANCH": utils.CI_COMMIT_BRANCH,
|
||||||
"GitBuild": utils.GitBuild,
|
"CI_COMMIT_TAG": utils.CI_COMMIT_TAG,
|
||||||
|
"CI_TAGGED": utils.CI_TAGGED,
|
||||||
|
"CI_BUILD": utils.CI_BUILD,
|
||||||
"TotalLinks": db.GetTotalLinks(),
|
"TotalLinks": db.GetTotalLinks(),
|
||||||
"TotalViews": db.GetTotalViews(),
|
"TotalViews": db.GetTotalViews(),
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,15 +1,22 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
var (
|
var (
|
||||||
GitCommitShort string
|
CI_COMMIT_SHORT_SHA string
|
||||||
GitBranch string
|
CI_COMMIT_BRANCH string
|
||||||
GitBuild bool
|
CI_COMMIT_TAG string
|
||||||
|
CI_TAGGED bool
|
||||||
|
CI_BUILD bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func Init_build_vars() {
|
func Init_build_vars() {
|
||||||
if GitCommitShort == "" && GitBranch == "" {
|
if CI_COMMIT_SHORT_SHA == "" && CI_COMMIT_BRANCH == "" {
|
||||||
GitBuild = false
|
CI_BUILD = false
|
||||||
} else {
|
} else {
|
||||||
GitBuild = true
|
CI_BUILD = true
|
||||||
|
}
|
||||||
|
if CI_COMMIT_TAG == "" {
|
||||||
|
CI_TAGGED = false
|
||||||
|
} else {
|
||||||
|
CI_TAGGED = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,9 @@ var ConfigLimiter limiter.Config = limiter.Config{
|
||||||
LimitReached: func(c *fiber.Ctx) error {
|
LimitReached: func(c *fiber.Ctx) error {
|
||||||
return c.Render("views/home", fiber.Map{
|
return c.Render("views/home", fiber.Map{
|
||||||
"ERR": "You have reached the limit of requests! Please check back later. (1 minute)",
|
"ERR": "You have reached the limit of requests! Please check back later. (1 minute)",
|
||||||
"GitCommitShort": GitCommitShort,
|
"CI_COMMIT_SHORT_SHA": CI_COMMIT_SHORT_SHA,
|
||||||
"GitBranch": GitBranch,
|
"CI_COMMIT_BRANCH": CI_COMMIT_BRANCH,
|
||||||
"GitBuild": GitBuild,
|
"CI_BUILD": CI_BUILD,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,8 +78,12 @@
|
||||||
<center>
|
<center>
|
||||||
Made with <a href="https://git.ucode.space/Phil/goshorly"><i class="fas fa-code-branch"></i>
|
Made with <a href="https://git.ucode.space/Phil/goshorly"><i class="fas fa-code-branch"></i>
|
||||||
Phil/goshorly</a>
|
Phil/goshorly</a>
|
||||||
{{ if .GitBuild }}
|
{{ if .CI_BUILD }}
|
||||||
| {{ .GitCommitShort }}/{{ .GitBranch }}
|
{{ if .CI_COMMIT_TAG }}
|
||||||
|
| {{ .CI_COMMIT_TAG }}
|
||||||
|
{{ else }}
|
||||||
|
| {{ .CI_COMMIT_SHORT_SHA }}/{{ .CI_COMMIT_BRANCH }}
|
||||||
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</center>
|
</center>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
Loading…
Reference in a new issue