From 3e1cd8389d24cde35a7836f5b09b6e9b6aae4c79 Mon Sep 17 00:00:00 2001 From: vx3r <vx3r@127-0-0-1.fr> Date: Tue, 25 Feb 2020 17:45:44 +0900 Subject: [PATCH] add version in back and front #16 / client can ignore global PK #17 / #18 email is now optional --- .github/workflows/dockerimage.yml | 1 + .gitlab-ci.yml | 7 ++-- Dockerfile | 8 ++--- api/api.go | 8 +++++ main.go | 6 +--- ui/package.json | 1 - ui/src/App.vue | 56 ++++++++++++++++++++++++------- ui/vue.config.js | 3 -- util/util.go | 2 ++ 9 files changed, 61 insertions(+), 31 deletions(-) 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 @@ <v-container> <router-view /> </v-container> + <Notification v-bind:notification="notification"/> </v-content> <v-footer app> - <span>License <a class="pr-1 pl-1" href="http://www.wtfpl.net/" target="_blank">WTFPL</a> © {{ new Date().getFullYear() }} Created with</span><v-icon class="pr-1 pl-1">mdi-heart</v-icon><span>by</span><a class="pr-1 pl-1" href="mailto:vx3r@127-0-0-1.fr">vx3r</a><v-spacer></v-spacer><span>Version: {{ VersionGitCommit }}</span> + <span>License <a class="pr-1 pl-1" href="http://www.wtfpl.net/" target="_blank">WTFPL</a> © {{ new Date().getFullYear() }} Created with</span><v-icon class="pr-1 pl-1">mdi-heart</v-icon><span>by</span><a class="pr-1 pl-1" href="mailto:vx3r@127-0-0-1.fr">vx3r</a><v-spacer></v-spacer><span>Version: {{ version }}</span> </v-footer> </v-app> </template> <script> -export default { - name: 'App', + import {ApiService} from "./services/ApiService"; + import Notification from './components/Notification' - data: () => ({ - VersionGitCommit: process.env.VUE_APP_GIT_HASH - }), + export default { + name: 'App', - mounted() { - console.log("Starting Wg Gen Web version: " + process.env.VUE_APP_GIT_HASH) - }, + components: { + Notification + }, - created () { - this.$vuetify.theme.dark = true - }, -}; + data: () => ({ + api: null, + version:'N/A', + notification: { + show: false, + color: '', + text: '', + }, + }), + + mounted() { + this.api = new ApiService(); + this.getVersion() + }, + + created () { + this.$vuetify.theme.dark = true + }, + + methods: { + getVersion() { + this.api.get('/server/version').then((res) => { + this.version = res.version; + }).catch((e) => { + this.notify('error', e.response.status + ' ' + e.response.statusText); + }); + }, + notify(color, msg) { + this.notification.show = true; + this.notification.color = color; + this.notification.text = msg; + } + } + }; </script> 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 -- GitLab