.gitlab-ci.yml 5.4 KB
Newer Older
Ernesto Rico Schmidt's avatar
Ernesto Rico Schmidt committed
1
image: golang:1.17
Christian Pointner's avatar
Christian Pointner committed
2

Christian Pointner's avatar
Christian Pointner committed
3
4
variables:
  GOPATH: "$CI_PROJECT_DIR/.gopath"
5
6
  GOFLAGS: -mod=readonly

7
8
9
10
11
12
13
14
.release-rules: &release-rules
  # rule to run job on a tag-reference which has the form number.number.number (semantic versioning)
  # or number.number.number-text (semantic versioning + release-name)
  # and where a Dockerfile exists
  - if: $CI_COMMIT_TAG =~ /^\d+[.]\d+[.]\d+$/ || $CI_COMMIT_TAG =~ /^\d+[.]\d+[.]\d+[-]\S+$/
    exists:
      - Dockerfile

15
16
cache:
  paths:
Christian Pointner's avatar
Christian Pointner committed
17
    - .gopath/
18
    - ui/assets_vfsdata.go
Christian Pointner's avatar
Christian Pointner committed
19
20
  key: default
  policy: pull
21

Christian Pointner's avatar
Christian Pointner committed
22
stages:
Christian Pointner's avatar
Christian Pointner committed
23
  - prepare
24
25
  - test
  - build
26
  - test-build
27
  - release
28

Christian Pointner's avatar
Christian Pointner committed
29
30
31
32
prepare:
  stage: prepare
  cache:
    policy: pull-push
33
  script:
Christian Pointner's avatar
Christian Pointner committed
34
35
36
    - mkdir -p .gopath
    - export GOPATH="$CI_PROJECT_DIR/.gopath"
    - go generate ./ui
37
38
    - go vet ./...

Christian Pointner's avatar
Christian Pointner committed
39

Christian Pointner's avatar
Christian Pointner committed
40
test-all-but-store:
41
42
43
  stage: test
  script:
    - go test -v -cover $(go list ./... | grep -v tank/store)
44
45

test-store-postgres:
46
47
  stage: test
  services:
48
    - postgres:10.19
49
50
51
52
53
54
55
  variables:
    POSTGRES_DB: "tank"
    POSTGRES_USER: "tank"
    POSTGRES_PASSWORD: "aura"
    AURA_TANK_TEST_DB_TYPE: "postgres"
    AURA_TANK_TEST_DB_HOST: "postgres"
  script:
56
    - go run contrib/waitfor-tcp.go postgres:5432 30
57
58
    - go test -v -cover ./store

Christian Pointner's avatar
Christian Pointner committed
59

Christian Pointner's avatar
Christian Pointner committed
60
build:
61
62
  stage: build
  script:
63
    # we should actually use `make build` here, see #30
64
65
66
    - go build -ldflags "-extldflags '-static'" -tags netgo -o $CI_PROJECT_DIR/tank ./cmd/tank
    ## sqlite needs cgo... :(
    ##- go build -o $CI_PROJECT_DIR/tank ./cmd/tank
67
68
  only:
    - master
69
70
71
  artifacts:
    paths:
      - tank
72

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
build-openapi-2-scheme:
  stage: build
  script:
    - go get -u github.com/swaggo/swag/cmd/swag
    - make api-docs
  artifacts:
    paths:
      - api/docs/swagger.yaml

build-openapi-3-scheme:
  stage: build
  image:
    name: openapitools/openapi-generator-cli:latest-release
  needs:
    - job: build-openapi-2-scheme
      artifacts: true
  script:
    - /usr/local/bin/docker-entrypoint.sh generate -i api/docs/swagger.yaml -o api/docs -g openapi-yaml --minimal-update
  artifacts:
    paths:
      - api/docs/openapi/openapi.yaml

95
96
97
98
99
docker:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
Christian Pointner's avatar
Christian Pointner committed
100
101
102
103
104
  cache:
    paths:
      - .docker/cache
    key: default
    policy: pull-push
105
  script:
106
107
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
    - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
108
109
  only:
    - master
110

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
test-scheme:
  stage: test-build
  needs:
    - job: build-openapi-3-scheme
      artifacts: true
  image:
    name: schemathesis/schemathesis:stable
    entrypoint: [""]
  services:
    - name: postgres:13
      alias: postgres
    - name: gitlab.servus.at:5050/aura/tank:master
      entrypoint: ["/bin/bash"]
      command:
        - '-c'
        - |
          # make sure postgres is up before starting tank
          while true; do 
            timeout 0.25 cat >/dev/null 2>&1 </dev/tcp/postgres/5432
            if [ "$?" = 124 ]; then break; fi
          done
          # disable authentication
          sed '/auth:/q' /etc/aura/tank.yaml | head -n-1 >/tmp/tank.yaml
          /usr/local/bin/tank --config /tmp/tank.yaml run --listen :"$TANK_PORT"
      alias: tank
  variables:
    POSTGRES_DB: tank
    POSTGRES_USER: tank
    POSTGRES_PASSWORD: aura
    TANK_DB_HOST: postgres
    TANK_PORT: 8040
    # Enable per-build-network so that service aliases are also
    # usable in the service containers themselves.
    FF_NETWORK_PER_BUILD: 1
  parallel:
    matrix:
      # see https://schemathesis.readthedocs.io/en/stable/cli.html#cmdoption-schemathesis-run-c
      - CHECKS: status_code_conformance
      - CHECKS: response_headers_conformance
      - CHECKS: response_schema_conformance
  script:
    - schemathesis run -c "$CHECKS" -b http://tank:"$TANK_PORT" --hypothesis-suppress-health-check too_slow api/docs/openapi/openapi.yaml

154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
docker-hub-push:
  # Use the official docker image.
  image: docker:latest
  stage: release
  variables:
    # the name of the image without version
    AURA_IMAGE_NAME: "autoradio/tank"
  services:
    - docker:dind
  before_script:
    # default repo is docker.io (aka docker hub)
    - docker login -u "$DOCKER_ID" -p "$DOCKER_HUB_AUTH"
  script:
    # every commit on main branch should build image as unstable
    # else it is from a tag (enforced by gitlab-ci rules)
    # hint: tags are references independent of branches
    - |
      if [ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]
        then docker build -t $AURA_IMAGE_NAME:unstable .
        else docker build -t $AURA_IMAGE_NAME -t $AURA_IMAGE_NAME:$CI_COMMIT_TAG .
      fi
    # TODO: maybe isolate docker build and docker push
    - docker push "$AURA_IMAGE_NAME" --all-tags
  rules: 
    - *release-rules
    # every commit on master/main branch should trigger a push to docker-hub as unstable without a release
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH 
      exists:
        - Dockerfile

release_job:
  stage: release
  needs: 
187
    - docker-hub-push
188
189
190
191
192
193
194
195
196
  image: registry.gitlab.com/gitlab-org/release-cli:latest
  rules: *release-rules
  script:
    - echo "this will be a release when there is a tag, but tags should be protected to be only createable by maintainers."
  release:
    name: 'Release $CI_COMMIT_TAG'
    description: ./CHANGELOG
    tag_name: '$CI_COMMIT_TAG'
    ref: '$CI_COMMIT_TAG'