-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.yml
224 lines (191 loc) · 7.57 KB
/
config.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
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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
version: 2
aliases:
- &deploy_ssh_fingerprint "e8:d7:da:b8:6a:fb:75:50:8d:5f:48:61:3c:46:49:50"
- &container_config
working_directory: /workspace/code
docker:
- image: drevops/ci-runner:24.11.0
environment:
COMPOSER_ALLOW_SUPERUSER: 1
DEPLOY_SSH_FINGERPRINT: *deploy_ssh_fingerprint
- &step_setup_git
run:
name: Setup git
command: |
mkdir -p "$HOME/.ssh/"
echo -e "Host *\n\tStrictHostKeyChecking no\n" > "$HOME/.ssh/config"
DEPLOY_SSH_FILE="${DEPLOY_SSH_FINGERPRINT//:}"
DEPLOY_SSH_FILE="$HOME/.ssh/id_rsa_${DEPLOY_SSH_FILE//\"}"
if [ -f "$DEPLOY_SSH_FILE" ]; then
echo "Found Deploy SSH key file $DEPLOY_SSH_FILE"
ssh-add -D > /dev/null
ssh-add "$DEPLOY_SSH_FILE"
fi
git config --global user.name "$DEPLOY_USER_NAME"
git config --global user.email "$DEPLOY_USER_EMAIL"
jobs:
build:
<<: *container_config
steps:
- attach_workspace:
at: /workspace
- checkout
- add_ssh_keys:
fingerprints:
- *deploy_ssh_fingerprint
- *step_setup_git
- run:
name: Validate composer.json
command: composer validate --ansi --strict
- run:
name: Install dependencies
command: composer install --ansi --no-progress --no-interaction --no-suggest --prefer-dist
- run:
name: Lint code
command: composer lint
- run:
name: Run tests
command: composer test
- persist_to_workspace:
root: /workspace
paths:
- code
# Demonstration of deployment in 'force-push' mode.
deploy-force-push:
<<: *container_config
steps:
- attach_workspace:
at: /workspace
- add_ssh_keys:
fingerprints:
- *deploy_ssh_fingerprint
- *step_setup_git
- checkout
# Test file will have a consistent name between deployments, but
# the contents will be added to on each deployment to simulate
# changes in the source repository.
- run:
name: Prepare test file.
command: |
export TEST_FILE="test-file--force-push--circleci--${CIRCLE_BRANCH//\//-}.txt"
echo "Deployment 1 for branch $CIRCLE_BRANCH" > $TEST_FILE
date "+%Y%m%d-%H%M%S" >> $TEST_FILE
cat $TEST_FILE
echo $TEST_FILE > $HOME/test-file.txt
- run:
name: Deployment 1
command: |
./git-artifact \
[email protected]:drevops/git-artifact-destination.git \
--branch=mode--force-push--circleci--[branch] \
--mode=force-push \
--log=$HOME/report--mode--force-push.txt \
-vvv
DEPLOYED_BRANCH=$(sed -n 's/Remote branch://p' $HOME/report--mode--force-push.txt | sed 's/ //g')
echo "Deployed to $DEPLOYED_BRANCH"
echo
echo "See https://github.com/drevops/git-artifact-destination/blob/$DEPLOYED_BRANCH/$(cat $HOME/test-file.txt)"
rm $HOME/report--mode--force-push.txt
- run:
name: Update the test file to simulate changes in the source repository.
command: |
export TEST_FILE="test-file--force-push--circleci--${CIRCLE_BRANCH//\//-}.txt"
echo "Deployment 2 for branch $CIRCLE_BRANCH" >> $TEST_FILE
date "+%Y%m%d-%H%M%S" >> $TEST_FILE
cat $TEST_FILE
- run:
name: Deployment 2
command: |
./git-artifact \
[email protected]:drevops/git-artifact-destination.git \
--branch=mode--force-push--circleci--[branch] \
--mode=force-push \
--log=$HOME/report--mode--force-push.txt \
-vvv
DEPLOYED_BRANCH=$(sed -n 's/Remote branch://p' $HOME/report--mode--force-push.txt | sed 's/ //g')
echo "Deployed to $DEPLOYED_BRANCH"
echo
echo "See https://github.com/drevops/git-artifact-destination/blob/$DEPLOYED_BRANCH/$(cat $HOME/test-file.txt)"
# Demonstration of deployment in 'branch' mode.
# Note that by design, pushing into the same branch will result in the failure
# of the second push. This is because the mode is intended to create a new
# branch per artifact deployment.
deploy-branch:
<<: *container_config
steps:
- attach_workspace:
at: /workspace
- add_ssh_keys:
fingerprints:
- *deploy_ssh_fingerprint
- *step_setup_git
- checkout
# Test file will have a consistent name between deployments, but
# the contents will be added to on each deployment to simulate
# changes in the source repository.
# Since each deployment in this mode creates a new branch, the test file
# will be pushed to a new branch each time and won't be updated in
# existing branches.
- run:
name: Prepare test file.
command: |
export TEST_FILE="test-file--branch--circleci--${CIRCLE_BRANCH//\//-}.txt"
echo "Deployment 1 for branch $CIRCLE_BRANCH" > $TEST_FILE
date "+%Y%m%d-%H%M%S" >> $TEST_FILE
cat $TEST_FILE
echo $TEST_FILE > $HOME/test-file.txt
- run:
name: Deployment 1
command: |
./git-artifact \
[email protected]:drevops/git-artifact-destination.git \
--branch=mode--branch--circleci--[branch]--[timestamp:Y-m-d_H-i] \
--mode=branch \
--log=$HOME/report--mode--branch.txt \
-vvv
DEPLOYED_BRANCH=$(sed -n 's/Remote branch://p' $HOME/report--mode--branch.txt | sed 's/ //g')
echo "Deployed to $DEPLOYED_BRANCH"
echo
echo "See https://github.com/drevops/git-artifact-destination/blob/$DEPLOYED_BRANCH/$(cat $HOME/test-file.txt)"
rm $HOME/report--mode--branch.txt
- run:
name: Deployment 2 - same branch
command: |
./git-artifact \
[email protected]:drevops/git-artifact-destination.git \
--branch=mode--branch--circleci--[branch]--[timestamp:Y-m-d_H-i] \
--mode=branch \
--log=$HOME/report--mode--branch.txt \
-vvv \
&& { echo "Expected to fail as repeated pushes to the same branch are not allowed, but succeeded" >&2; exit 1; } || echo "Failed as expected"
- run:
name: Update the test file to simulate changes in the source repository.
command: |
export TEST_FILE="test-file--branch--circleci--${CIRCLE_BRANCH//\//-}.txt"
echo "Deployment 2 for branch $CIRCLE_BRANCH" > $TEST_FILE
date "+%Y%m%d-%H%M%S" >> $TEST_FILE
cat $TEST_FILE
- run:
name: Deployment 2 - new branch
command: |
./git-artifact \
[email protected]:drevops/git-artifact-destination.git \
--branch=mode--branch--circleci--[branch]--[timestamp:Y-m-d_H-i-s] \
--mode=branch \
--log=$HOME/report--mode--branch.txt \
-vvv
DEPLOYED_BRANCH=$(sed -n 's/Remote branch://p' $HOME/report--mode--branch.txt | sed 's/ //g')
echo "Deployed to $DEPLOYED_BRANCH"
echo
echo "See https://github.com/drevops/git-artifact-destination/blob/$DEPLOYED_BRANCH/$(cat $HOME/test-file.txt)"
workflows:
version: 2
main:
jobs:
- build
- deploy-force-push:
requires:
- build
- deploy-branch:
requires:
- build