variables: APP_NAME: "dnspod-watch" APP_VERSION: 1.0.0 NAMESPACE: app REGISTRY: "docker.io" REPOSITORY: "app/dnspod-watch" GO111MODULE: "on" GOPROXY: "https://goproxy.cn,direct" GOPATH: "$CI_PROJECT_DIR/.cache" GOLANGCI_LINT_CACHE: "$CI_PROJECT_DIR/.lint-cache" stages: - test - build - docker - deploy test-job: stage: test image: golang:1.19 cache: key: go-cache paths: - .cache script: - go test -v ./... lint-job: stage: test image: golangci/golangci-lint:v1.52 cache: key: lint-cache paths: - .lint-cache script: - golangci-lint run build: stage: build image: golang:1.19-alpine3.16 rules: - if: $CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH =~ /^release\/.*$/ cache: key: go-cache paths: - .cache script: - CGO_ENABLE=0 GOOS=linux GOARCH=amd64 go build -o $APP_NAME ./cmd/app artifacts: expire_in: 1 week paths: - $APP_NAME build-docker: stage: docker image: docker:rc rules: - if: $CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH =~ /^release\/.*$/ variables: DOCKER_HOST: tcp://docker-dind:2375 before_script: - docker login $REGISTRY --username $DOCKER_USERNAME --password $DOCKER_PASSWORD script: - docker build . --build-arg APP_NAME=$APP_NAME -f deploy/docker/Dockerfile -t $REGISTRY/$REPOSITORY:$CI_COMMIT_SHORT_SHA - docker push $REGISTRY/$REPOSITORY:$CI_COMMIT_SHORT_SHA deploy: stage: deploy image: alpine/helm:3.9.0 rules: - if: $CI_COMMIT_BRANCH == "main" script: - cd deploy/helm - | helm upgrade --install --namespace $NAMESPACE $APP_NAME . \ --set image.tag=$CI_COMMIT_SHORT_SHA --set image.repository=$REGISTRY/$REPOSITORY \ --set etcdConfig.password=$ETCD_CONFIG_PASSWORD