From bab862a084a61619bf98dfdf1b4eb85c7c2c3de3 Mon Sep 17 00:00:00 2001 From: Vassiliy Yegorov Date: Wed, 7 Sep 2022 11:40:09 +0700 Subject: [PATCH] up --- ci/.gitlab-ci.yml | 24 ++++++++++++++---------- ci/app/main.go | 6 ++++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/ci/.gitlab-ci.yml b/ci/.gitlab-ci.yml index f66cfd7..0828062 100644 --- a/ci/.gitlab-ci.yml +++ b/ci/.gitlab-ci.yml @@ -10,18 +10,26 @@ variables: GITLAB: git.bildme.ru IMAGE_NAME: $REGISTRY/$CI_PROJECT_PATH:latest RELEASE_NAME: go-site - VERSION: 0.0.3 + VERSION: 0.0.5 PACKAGE_REGISTRY_URL: https://${GITLAB}/api/v4/projects/${CI_PROJECT_ID}/packages/generic/${RELEASE_NAME}/${VERSION} stages: - build - push +- artifacts - release - deploy +.rules: &rules + rules: + - if: $CI_COMMIT_TAG + when: never + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + build_main: stage: build image: golang:latest + <<: *rules script: - cd app - CGO_ENABLED=0 GOOS=linux GO111MODULE=auto go build -a -ldflags="-X 'main.Version=v${VERSION}'" -installsuffix cgo -o go-site . @@ -33,6 +41,7 @@ build_main: push_image: stage: push + <<: *rules before_script: - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $REGISTRY script: @@ -43,10 +52,7 @@ push_image: package: stage: release - rules: - - if: $CI_COMMIT_TAG - when: never - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + <<: *rules before_script: - apk add curl script: @@ -57,10 +63,7 @@ package: release: stage: release image: registry.gitlab.com/gitlab-org/release-cli:latest - rules: - - if: $CI_COMMIT_TAG - when: never - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + <<: *rules script: - echo "Release ${RELEASE_NAME}" release: @@ -74,8 +77,9 @@ release: url: '${PACKAGE_REGISTRY_URL}/${RELEASE_NAME}' deploy_prod: - image: hub.realmanual.ru/pub/openssh-client:latest stage: deploy + image: hub.realmanual.ru/pub/openssh-client:latest + <<: *rules variables: DOCKER_SERVER: 192.168.9.199 before_script: diff --git a/ci/app/main.go b/ci/app/main.go index 953c692..2a00c34 100644 --- a/ci/app/main.go +++ b/ci/app/main.go @@ -6,8 +6,10 @@ import ( "fmt" ) +var Version = "0.0.1" + func indexHandler(w http.ResponseWriter, r *http.Request) { - w.Write([]byte("

Hello World!

")) + w.Write([]byte("

Hello World, im ver:"+Version+" !

")) } func main() { @@ -16,7 +18,7 @@ func main() { port = "3000" } - fmt.Print("\nim run in http://127.0.0.1:", port) + fmt.Print("\nVersion:", Version, ", Im run in http://127.0.0.1:", port) mux := http.NewServeMux() mux.HandleFunc("/", indexHandler)