diff --git a/.github/workflows/dockerimage.yml b/.github/workflows/dockerimage.yml index facbe74..16d3808 100644 --- a/.github/workflows/dockerimage.yml +++ b/.github/workflows/dockerimage.yml @@ -39,3 +39,4 @@ jobs: imageName: ${{ env.DOCKER_IMAGE_NAME }} dockerHubUser: ${{ secrets.DOCKER_LOGIN_USERNAME }} dockerHubPassword: ${{ secrets.DOCKER_LOGIN_PASSWORD }} + buildArg: COMMIT=${{ GITHUB_SHA::8 }} \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 545e303..ff33b6d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,7 +7,7 @@ build-back: stage: build artifacts image: golang:latest script: - - GOOS=linux GOARCH=amd64 go build -ldflags "-X main.VersionGitCommit=${CI_COMMIT_SHORT_SHA}" -o ${CI_PROJECT_NAME}-linux-amd64 + - GOOS=linux GOARCH=amd64 go build -ldflags="-X 'gitlab.127-0-0-1.fr/vx3r/wg-gen-web/util.Version=${CI_COMMIT_SHORT_SHA}'" -o ${CI_PROJECT_NAME}-linux-amd64 artifacts: paths: - ${CI_PROJECT_NAME}-linux-amd64 @@ -16,9 +16,6 @@ build-front: stage: build artifacts image: node:10-alpine script: - - apk update - - apk upgrade - - apk add --no-cache git - cd ./ui - npm install - npm run build @@ -32,7 +29,7 @@ build: image: docker:latest script: - docker info - - docker build --network br_docker --tag ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA} . + - docker build --build-arg COMMIT=${CI_COMMIT_SHORT_SHA} --network br_docker --tag ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA} . push: stage: push docker hub diff --git a/Dockerfile b/Dockerfile index 1ff6002..6276efa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,16 @@ +ARG COMMIT="N/A" + FROM golang:alpine AS build-back WORKDIR /app -RUN apk update && apk upgrade && apk add --no-cache git +ARG COMMIT COPY . . -RUN GIT_COMMIT=$(git rev-parse --short HEAD) && go build -ldflags "-X main.VersionGitCommit=$GIT_COMMIT" go build -o wg-gen-web-linux +RUN go build -ldflags="-X 'gitlab.127-0-0-1.fr/vx3r/wg-gen-web/util.Version=${COMMIT}'" -o wg-gen-web-linux FROM node:10-alpine AS build-front WORKDIR /app -RUN apk update && apk upgrade && apk add --no-cache git COPY ui/package*.json ./ RUN npm install COPY ui/ ./ -COPY .git . RUN npm run build FROM alpine diff --git a/api/api.go b/api/api.go index f1b7097..b527996 100644 --- a/api/api.go +++ b/api/api.go @@ -6,6 +6,7 @@ import ( "github.com/skip2/go-qrcode" "gitlab.127-0-0-1.fr/vx3r/wg-gen-web/core" "gitlab.127-0-0-1.fr/vx3r/wg-gen-web/model" + "gitlab.127-0-0-1.fr/vx3r/wg-gen-web/util" "net/http" ) @@ -27,6 +28,7 @@ func ApplyRoutes(r *gin.Engine) { { server.GET("", readServer) server.PATCH("", updateServer) + server.GET("/version", version) } } @@ -200,3 +202,9 @@ func updateServer(c *gin.Context) { c.JSON(http.StatusOK, client) } + +func version(c *gin.Context) { + c.JSON(http.StatusOK, gin.H{ + "version": util.Version, + }) +} diff --git a/main.go b/main.go index 3f93063..a08072f 100644 --- a/main.go +++ b/main.go @@ -15,10 +15,6 @@ import ( "path/filepath" ) -var ( - VersionGitCommit string -) - func init() { log.SetFormatter(&log.TextFormatter{}) log.SetOutput(os.Stderr) @@ -26,7 +22,7 @@ func init() { } func main() { - log.Infof("Starting Wg Gen Web version: %s", VersionGitCommit) + log.Infof("Starting Wg Gen Web version: %s", util.Version) // load .env environment variables err := godotenv.Load() diff --git a/ui/package.json b/ui/package.json index 5d2c28e..64aff46 100644 --- a/ui/package.json +++ b/ui/package.json @@ -8,7 +8,6 @@ }, "dependencies": { "axios": "^0.19.2", - "git-describe": "^4.0.4", "is-cidr": "^3.1.0", "moment": "^2.24.0", "vue": "^2.6.10", diff --git a/ui/src/App.vue b/ui/src/App.vue index d63b966..86b54f8 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -24,29 +24,59 @@ + - License WTFPL © {{ new Date().getFullYear() }} Created withmdi-heartbyvx3rVersion: {{ VersionGitCommit }} + License WTFPL © {{ new Date().getFullYear() }} Created withmdi-heartbyvx3rVersion: {{ version }} diff --git a/ui/vue.config.js b/ui/vue.config.js index 64b7ac6..16260bb 100644 --- a/ui/vue.config.js +++ b/ui/vue.config.js @@ -1,6 +1,3 @@ -const {gitDescribe, gitDescribeSync} = require('git-describe'); -process.env.VUE_APP_GIT_HASH = gitDescribeSync().hash; - module.exports = { devServer: { port: 8081, diff --git a/util/util.go b/util/util.go index 6fa8690..225b632 100644 --- a/util/util.go +++ b/util/util.go @@ -10,6 +10,8 @@ import ( var ( RegexpEmail = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$") + // pushed build time + Version string ) // ReadFile file content