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:
commit
510e7dad83
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,10 +8,12 @@ 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,
|
||||||
"TotalLinks": db.GetTotalLinks(),
|
"CI_TAGGED": utils.CI_TAGGED,
|
||||||
"TotalViews": db.GetTotalViews(),
|
"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{
|
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,
|
||||||
"TotalLinks": db.GetTotalLinks(),
|
"CI_TAGGED": utils.CI_TAGGED,
|
||||||
"TotalViews": db.GetTotalViews(),
|
"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{
|
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,
|
||||||
"TotalLinks": db.GetTotalLinks(),
|
"CI_TAGGED": utils.CI_TAGGED,
|
||||||
"TotalViews": db.GetTotalViews(),
|
"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{
|
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,
|
||||||
"TotalLinks": db.GetTotalLinks(),
|
"CI_TAGGED": utils.CI_TAGGED,
|
||||||
"TotalViews": db.GetTotalViews(),
|
"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{
|
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,
|
||||||
"TotalLinks": db.GetTotalLinks(),
|
"CI_TAGGED": utils.CI_TAGGED,
|
||||||
"TotalViews": db.GetTotalViews(),
|
"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{
|
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,
|
||||||
"TotalLinks": db.GetTotalLinks(),
|
"CI_TAGGED": utils.CI_TAGGED,
|
||||||
"TotalViews": db.GetTotalViews(),
|
"CI_BUILD": utils.CI_BUILD,
|
||||||
|
"TotalLinks": db.GetTotalLinks(),
|
||||||
|
"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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,10 @@ var ConfigLimiter limiter.Config = limiter.Config{
|
||||||
Expiration: 60 * time.Second,
|
Expiration: 60 * time.Second,
|
||||||
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