-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path.gitlab-ci.yml
89 lines (80 loc) · 2.35 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
variables:
TAG_LATEST: $CI_REGISTRY/$GITLAB_USER_LOGIN/portugolweb:latest
TAG_COMMIT: $CI_REGISTRY/$GITLAB_USER_LOGIN/portugolweb:$CI_COMMIT_SHORT_SHA
DEV_BRANCH: "develop"
.base-rules:
# https://how-to.dev/how-to-set-up-monorepo-build-in-gitlab-ci
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: always
- if: '$CI_PIPELINE_SOURCE == "push"'
when: never
- if: $CI_COMMIT_TAG
when: never
# - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
# changes:
# - $RULES_CHANGES_PATH
- when: manual
allow_failure: true
.test-rules:
extends: .base-rules
rules:
- if: $CI_COMMIT_BRANCH == $DEV_BRANCH
when: always
stages:
- test
- build
- publish
cache:
key: "$CI_PROJECT_ID"
paths:
- node_modules/ # npm install
- dist/ # webpack
test-job:
stage: test
image: node:alpine
extends: .test-rules
needs: []
script:
- npm install
- npm run test
build-job:
stage: build
image: node:alpine
extends: .base-rules
needs: ["test-job"]
script:
- npm install
- npm run build
- npm run buildace
# https://blog.callr.tech/building-docker-images-with-gitlab-ci-best-practices/
publish-nodejs-exemplo:
stage: publish
extends: .base-rules
needs: ["build-job"]
# do not use latest
image: docker:dind
script:
# https://stackoverflow.com/questions/45344158/multiple-dockerignore-files-in-same-directory
- export DOCKER_BUILDKIT=1
# fetches the latest image (not failing if image is not found)
- docker pull $TAG_LATEST || true
# builds the project, passing proxy variables, using OCI labels
# notice the cache-from, which is going to use the image we just pulled locally
# the built image is tagged locally with the commit SHA, and then pushed to
# the GitLab registry
- >
docker build
--pull
--cache-from $TAG_LATEST
--label "org.opencontainers.image.title=$CI_PROJECT_TITLE"
--label "org.opencontainers.image.url=$CI_PROJECT_URL"
--label "org.opencontainers.image.created=$CI_JOB_STARTED_AT"
--label "org.opencontainers.image.revision=$CI_COMMIT_SHA"
--label "org.opencontainers.image.version=$CI_COMMIT_REF_NAME"
--tag $TAG_COMMIT
-f production.Dockerfile
.
- docker tag $TAG_COMMIT $TAG_LATEST
- docker push "$TAG_COMMIT"
- docker push "$TAG_LATEST"