stages: - test - build - validate variables: DOCKER_IMAGE: docker.io/uhryniuk/go-server DOCKER_TAG: $CI_COMMIT_SHORT_SHA # Go build job go:build: stage: test image: golang:1.23-alpine cache: key: go-mod paths: - .go/pkg/mod/ variables: GOPATH: $CI_PROJECT_DIR/.go script: - go build -o interview-server . artifacts: paths: - interview-server expire_in: 1 hour # Go unit tests go:test: stage: test image: golang:1.23-alpine cache: key: go-mod paths: - .go/pkg/mod/ variables: GOPATH: $CI_PROJECT_DIR/.go script: - go test -v -cover # Docker build and push docker:build: stage: build image: docker:24 services: - docker:24-dind before_script: - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin docker.io script: - docker build -t $DOCKER_IMAGE:$DOCKER_TAG -t $DOCKER_IMAGE:latest . - docker push $DOCKER_IMAGE:$DOCKER_TAG - docker push $DOCKER_IMAGE:latest only: - main - tags # Helm lint helm:lint: stage: validate image: name: alpine/helm:4.0 entrypoint: [""] script: - helm lint ./helm # Helm template validation helm:template: stage: validate image: name: alpine/helm:4.0 entrypoint: [""] script: - helm version - helm template test-release ./helm --debug > helm-output.yaml 2>&1 || (cat helm-output.yaml && exit 1) - | if [ ! -s helm-output.yaml ]; then echo "Error: Helm template output is empty" exit 1 fi - echo "Helm template validation successful" artifacts: paths: - helm-output.yaml expire_in: 1 day