-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path.gitlab-ci.yml
112 lines (89 loc) · 2.6 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
stages:
- test
- build
- scan
.rails_template: &rails_template
image: ruby:2.6.5-alpine
services:
- postgres:latest
variables:
POSTGRES_DB: gitlab_ci_test
POSTGRES_USER: runner
POSTGRES_HOST_AUTH_METHOD: trust
stage: test
cache:
key:
files:
- Gemfile.lock
- package.json
paths:
- vendor/bundle
- node_modules
before_script:
- apk add alpine-sdk chromium-chromedriver nodejs postgresql-dev tzdata yarn
- bundle check --path vendor/bundle || bundle install --path vendor/bundle
- yarn install
- cp config/database.yml.gitlab config/database.yml
- cp .env.example .env
rails_test:
<<: *rails_template
script:
- bundle exec rake
rails_style:
<<: *rails_template
script:
- bundle exec rake check_style
bundle_audit:
<<: *rails_template
script:
- bundle exec bundle audit update
- bundle exec bundle audit --ignore CVE-2021-32740
yarn_audit:
<<: *rails_template
script:
- yarn run improved-yarn-audit
.build_template: &build_template
image: docker:latest
stage: build
services:
- docker:dind
variables:
DOCKER_TLS_CERTDIR: ""
before_script:
- docker login -u "gitlab-ci-token" -p "$CI_BUILD_TOKEN" $CI_REGISTRY
rules:
# Run when a new tag is cut
- if: $CI_COMMIT_TAG
build_rails:
<<: *build_template
script:
- docker build -f Dockerfile --pull -t "$CI_REGISTRY_IMAGE/rails:$CI_COMMIT_TAG" .
- docker push "$CI_REGISTRY_IMAGE/rails:$CI_COMMIT_TAG"
include:
- template: Container-Scanning.gitlab-ci.yml
# Override the defaults in the container_scanning template job
container_scanning:
# Only run after the build stage has passed
stage: scan
# The container scanner will pull from $CI_APPLICATION_REPOSITORY:$CI_APPLICATION_TAG
variables:
CI_APPLICATION_REPOSITORY: $CI_REGISTRY_IMAGE/rails
CI_APPLICATION_TAG: $CI_COMMIT_TAG
DOCKERFILE_PATH: Dockerfile
before_script:
# Scheduled pipelines won't have a commit tag so we set the $CI_APPLICATION_TAG manually
# This will set $CI_APPLICATION_TAG to the most recent commit
- >
if [[ "$CI_PIPELINE_SOURCE" == "schedule" ]]; then
apk add --update --no-cache git
git fetch --tags --force
export CI_APPLICATION_TAG=$(git tag --list --sort=committerdate | tail -n 1)
echo "Checking $CI_APPLICATION_REPOSITORY:$CI_APPLICATION_TAG"
fi
# The pipeline will run only if a rule matches
rules:
# Run on scheduled pipelines
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: always
# Run when a new tag is cut
- if: $CI_COMMIT_TAG