73 lines
2.0 KiB
YAML
73 lines
2.0 KiB
YAML
stages:
|
|
- build
|
|
- package
|
|
- deploy
|
|
|
|
golang-build:
|
|
only:
|
|
- master
|
|
- uat
|
|
- test
|
|
stage: build
|
|
image: golang:1.23.0
|
|
before_script:
|
|
- mkdir -p /root/go/pkg/mod
|
|
- env && echo $GOPATH
|
|
cache: [ ]
|
|
variables:
|
|
GOPATH: /root/go
|
|
script:
|
|
- |
|
|
export GOPROXY="https://goproxy.cn"
|
|
export GOPRIVATE="code.mylomen.com"
|
|
export GONOPROXY="code.mylomen.com"
|
|
export GONOSUMDB="code.mylomen.com"
|
|
|
|
go mod download
|
|
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -mod=mod -ldflags="-w -s" main.go
|
|
artifacts:
|
|
paths:
|
|
- ./main
|
|
expire_in: 1 hour
|
|
|
|
docker-package:
|
|
only:
|
|
- master
|
|
- uat
|
|
- test
|
|
stage: package
|
|
script:
|
|
- |
|
|
docker info
|
|
APP_NAME=$(basename "$PWD")
|
|
echo ${APP_NAME}
|
|
docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
|
|
tag="${CI_REGISTRY}/mylomen/${APP_NAME}:${CI_COMMIT_BRANCH}-${CI_COMMIT_SHA}"
|
|
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag" && pwd && ls && ifconfig
|
|
echo "docker build -t \"${tag}\" ."
|
|
docker build -t "${tag}" .
|
|
docker push "${tag}"
|
|
echo "CURRENT_IMAGE_URL=${tag}" > docker-build.env
|
|
echo "APP_NAME=${APP_NAME}" >> docker-build.env
|
|
docker rmi "${tag}"
|
|
rm ./main
|
|
artifacts:
|
|
reports:
|
|
dotenv: docker-build.env
|
|
|
|
deploy:
|
|
only:
|
|
- master
|
|
# when: manual
|
|
image: laoma/nomad:v1
|
|
stage: deploy
|
|
script:
|
|
- nomad status -address=http://10.0.12.8:4646 -token=${PROD_NOMAD_TOKEN}
|
|
- envsubst < nomad-job-test.tpl.hcl > nomad-job.hcl
|
|
- cat nomad-job.hcl
|
|
- nomad validate nomad-job.hcl
|
|
- nomad plan -address=http://10.0.12.8:4646 -token=${PROD_NOMAD_TOKEN} nomad-job.hcl 2>&1 |sed 's/\(password[^ \t]*[ \t]*\).*/\1 ... /' |tee plan.log || echo
|
|
- export INDEX=$(grep -E -o -- '-check-index [0-9]+' plan.log |tr -dc 0-9)
|
|
- nomad run -check-index $INDEX -token=${PROD_NOMAD_TOKEN} -address=http://10.0.12.8:4646 nomad-job.hcl
|
|
dependencies:
|
|
- docker-package |