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 \
|
||||
--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
|
||||
|
|
|
@ -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 /
|
||||
|
|
|
@ -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(),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
},
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue