-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
119 lines (109 loc) · 3.06 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
113
114
115
116
117
118
119
# This file is a template, and might need editing before it works on your project.
# This is the Gradle build system for JVM applications
# https://gradle.org/
# https://github.com/gradle/gradle
# Disable the Gradle daemon for Continuous Integration servers as correctness
# is usually a priority over speed in CI environments. Using a fresh
# runtime for each build is more reliable since the runtime is completely
# isolated from any previous builds.
variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
CI_REGISTRY: "registry.lan.yukina.tw:5000"
CI_REGISTRY_IMAGE: "shuvi/dcdos"
stages:
- build
- test
- package
- push
- deploy
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
build:
image: gradle:7-jdk11
stage: build
script: gradle --build-cache assemble
cache:
key: build-cache
paths:
- .gradle
- build
artifacts:
paths:
- build/libs/*.jar
expire_in: 1 week
except:
changes:
- "*.md"
# test:
# image: gradle:7-jdk11
# stage: test
# script: gradle check
# cache:
# key: "$CI_COMMIT_REF_NAME"
# policy: pull
# paths:
# - build
# - .gradle
package:
stage: package
image: docker:latest
script:
- echo -n $REGISTRY_PASSWORD | docker login -u $REGISTRY_USERNAME --password-stdin $CI_REGISTRY
- docker pull $CI_REGISTRY/$CI_REGISTRY_IMAGE:latest || true
- >
docker build
--pull
--build-arg VCS_REF=$CI_COMMIT_SHA
--build-arg VCS_URL=$CI_PROJECT_URL
--cache-from $CI_REGISTRY/$CI_REGISTRY_IMAGE:latest
--tag $CI_REGISTRY/$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
.
- docker push $CI_REGISTRY/$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
except:
changes:
- "*.md"
Push latest:
image: docker:latest
variables:
GIT_STRATEGY: none
stage: push
only:
- master
script:
- echo -n $REGISTRY_PASSWORD | docker login -u $REGISTRY_USERNAME --password-stdin $CI_REGISTRY
- docker pull $CI_REGISTRY/$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- docker tag $CI_REGISTRY/$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY/$CI_REGISTRY_IMAGE:latest
- docker push $CI_REGISTRY/$CI_REGISTRY_IMAGE:latest
except:
changes:
- "*.md"
Push tag:
image: docker:latest
variables:
GIT_STRATEGY: none
stage: push
only:
- tags
script:
- echo -n $REGISTRY_PASSWORD | docker login -u $REGISTRY_USERNAME --password-stdin $CI_REGISTRY
- docker pull $CI_REGISTRY/$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- docker tag $CI_REGISTRY/$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY/$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
- docker push $CI_REGISTRY/$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
except:
changes:
- "*.md"
deploy:
stage: deploy
script:
- apk upgrade && apk update
- apk add openssh-client
- mkdir -p ~/.ssh
- echo "$PRODUCTION_ID_RSA" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 700 ~/.ssh/id_rsa
- eval "$(ssh-agent -s)"
- ssh-add ~/.ssh/id_rsa
- ssh-keyscan -H 'production.lan.yukina.tw' >> ~/.ssh/known_hosts
- ssh gitlab@production.lan.yukina.tw
except:
changes:
- "*.md"