-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
executable file
·177 lines (170 loc) · 5.39 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
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
stages:
- init
- test
- build
- push
- deploy
- install
.set_colors: &set_colors
- export BLUE='\033[0;34m'
- export YELLOW='\033[0;33m'
- export RED='\033[0;31m'
- export NC='\033[0m' #No Color
- export NOW=$(date "+%Y-%m-%d_%H-%M-%S")
init:
image: registry.sindria.org/docker-images/deployer:latest
stage: init
variables:
CMS_NAME: "WordPress"
CMS_VERSION: "latest"
tags:
- default
only:
- tags
cache:
key: "${CI_COMMIT_REF_SLUG}"
paths:
- public
before_script:
- *set_colors
script:
- echo -e "${BLUE}Init CMS...${NC}"
- echo #
- echo -e "${BLUE}Creating temporary directory...${NC}"
- mkdir -p /cms
- cd /cms
- echo #
- echo -e "${BLUE}Downloading $CMS_NAME $CMS_VERSION version...${NC}"
- wget https://it.wordpress.org/latest-it_IT.tar.gz
- echo #
- echo -e "${BLUE}Extracting $CMS_NAME...${NC}"
- tar xzvf latest-it_IT.tar.gz
- echo #
- echo -e "${BLUE}Merging...${NC}"
- rsync -ra /cms/wordpress/ $CI_PROJECT_DIR/public/
- echo #
- cd $CI_PROJECT_DIR/public
- cp wp-config.production.php wp-config.php
- cp .htaccess.production .htaccess
- echo -e "${BLUE}Cleaning...${NC}"
- rm -Rf $CI_PROJECT_DIR/public/wp-content/themes/twenty*
- rm -Rf $CI_PROJECT_DIR/public/wp-content/plugins/hello.php
- rm -Rf $CI_PROJECT_DIR/public/wp-content/plugins/akismet
- rm -Rf $CI_PROJECT_DIR/public/wp-content/themes/resources/.gitignore
- rm -Rf $CI_PROJECT_DIR/public/wp-content/mu-plugins/.gitignore
- echo "Init Success"
artifacts:
paths:
- public
expire_in: 7 days
test:build:docker:
image: registry.sindria.org/docker-images/image-builder:latest
stage: test
when: manual
variables:
IMAGE_NAMESPACE: "tennisclubarzachena-team"
IMAGE_NAME: "tennisclubarzachena-blog"
tags:
- docker
only:
- branches
before_script:
- *set_colors
script:
- echo -e "${BLUE}Building image...${NC}"
- chmod +x ./.ci/build.sh
- ./.ci/build.sh 1000 test
- cowsay "Build Success"
- echo -e "${BLUE}Cleaning local registry...${NC}"
- docker image rm registry.sindria.org/$IMAGE_NAMESPACE/$IMAGE_NAME:test
- docker image rm registry.sindria.org/$IMAGE_NAMESPACE/$IMAGE_NAME:latest
- cowsay -f tux "Test Build Success"
build:docker:
image: registry.sindria.org/docker-images/image-builder:latest
stage: build
variables:
IMAGE_NAMESPACE: "tennisclubarzachena-team"
IMAGE_NAME: "tennisclubarzachena-blog"
tags:
- docker
only:
- tags
before_script:
- *set_colors
script:
- echo -e "${BLUE}Building image...${NC}"
- chmod +x ./.ci/build.sh
- ./.ci/build.sh 1000 $CI_COMMIT_TAG
- cowsay -f tux "Build Success"
push:docker:
image: registry.sindria.org/docker-images/image-builder:latest
stage: push
variables:
IMAGE_NAMESPACE: "tennisclubarzachena-team"
IMAGE_NAME: "tennisclubarzachena-blog"
tags:
- docker
only:
- tags
before_script:
- *set_colors
script:
- echo -e "${BLUE}Pushing image into registry...${NC}"
- docker push registry.sindria.org/$IMAGE_NAMESPACE/$IMAGE_NAME:$CI_COMMIT_TAG
- docker push registry.sindria.org/$IMAGE_NAMESPACE/$IMAGE_NAME:latest
- echo #
- echo -e "${BLUE}Cleaning local registry...${NC}"
- docker image rm registry.sindria.org/$IMAGE_NAMESPACE/$IMAGE_NAME:$CI_COMMIT_TAG
- docker image rm registry.sindria.org/$IMAGE_NAMESPACE/$IMAGE_NAME:latest
- echo #
- cowsay -f dragon "Well Done! New docker image is now on your registry."
deploy:app:
image: registry.sindria.org/docker-images/deployer:latest
stage: deploy
variables:
IMAGE_NAME: "tennisclubarzachena-blog"
IMAGE_NAMESPACE: "tennisclubarzachena-team"
APP_NAMESPACE: "tennisclubarzachena.it"
SERVER: "tennisclubarzachena.sindria.org"
tags:
- default
only:
- tags
before_script:
- *set_colors
script:
- ssh $SERVER "docker stop $IMAGE_NAME"
- ssh $SERVER "docker rm $IMAGE_NAME"
- ssh $SERVER "docker image rm registry.sindria.org/$IMAGE_NAMESPACE/$IMAGE_NAME:latest" || echo -e "${YELLOW}Image not present into this local registry${NC}"
- ssh $SERVER "cd /home/sindria/$APP_NAMESPACE; docker-compose up -d"
- cowsay "Deploy Success"
install:app:
image: registry.sindria.org/docker-images/deployer:latest
stage: install
when: manual
variables:
IMAGE_NAME: "tennisclubarzachena-blog"
IMAGE_NAMESPACE: "tennisclubarzachena-team"
APP_NAMESPACE: "tennisclubarzachena.it"
SERVICE_NAMESPACE: "sindriainc"
SERVICE_NAME: "migrations"
tags:
- default
only:
- branches
- tags
before_script:
- *set_colors
script:
- echo -e "${BLUE}Setting up...${NC}"
- ssh $SERVER "mkdir -p /home/sindria/$IMAGE_NAME"
- cd $CI_PROJECT_DIR
- cp .env.production .env
- cp docker-compose.production.yml docker-compose.yml
- rsync -rav -e "ssh" --exclude-from=.git --delete $CI_PROJECT_DIR/ $SERVER:/home/sindria/$IMAGE_NAME/
- ssh $SERVER "cd /home/sindria/$IMAGE_NAME; docker-compose up -d"
- ssh $SERVER "bash /home/sindria/$IMAGE_NAME/bin/fresh_install.sh"
- ssh $SERVER "cd /home/sindria/$IMAGE_NAME; docker-compose down"
- ssh $SERVER "docker image rm $SERVICE_NAMESPACE/$SERVICE_NAME:latest" || echo -e "${YELLOW}Image not present into this local registry${NC}"
- ssh $SERVER "cd /home/sindria; rm -rf $IMAGE_NAME"
- cowsay "Installation Complete"