-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
174 lines (156 loc) · 6.49 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
---
.script-git-submodule: &script-git-submodule
- |
git submodule sync --recursive
git submodule update --init --recursive
.script-linters: &script-linters
- |
flake8
yamllint .
ansible-lint
.script-bootstrap-python: &script-bootstrap-python
- |
if ! [[ -x "$(command -v pipx)" ]]; then
export DEBIAN_FRONTEND="noninteractive"
echo "deb http://downloadcontent.opensuse.org/repositories/home:/alvistack/xUbuntu_24.04/ /" | sudo tee /etc/apt/sources.list.d/home:alvistack.list
curl -fsSL https://downloadcontent.opensuse.org/repositories/home:alvistack/xUbuntu_24.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_alvistack.gpg > /dev/null
sudo -E apt-get update
sudo -E apt-get install -y bzip2 ca-certificates curl flake8 gcc gnupg gzip iproute2 pipx procps python3 python3-apt python3-cryptography python3-flake8 python3-jmespath python3-lxml python3-netaddr python3-pip python3-setuptools python3-venv python3-virtualenv python3-wheel sudo tar unzip xz-utils yamllint zip
fi
sh -x -c "python3 --version"
sh -x -c "pipx --version"
sh -x -c "flake8 --version"
sh -x -c "yamllint --version"
.script-bootstrap-ansible: &script-bootstrap-ansible
- |
if ! [[ -x "$(command -v ansible)" ]]; then
export DEBIAN_FRONTEND="noninteractive"
echo "deb http://downloadcontent.opensuse.org/repositories/home:/alvistack/xUbuntu_24.04/ /" | sudo tee /etc/apt/sources.list.d/home:alvistack.list
curl -fsSL https://downloadcontent.opensuse.org/repositories/home:alvistack/xUbuntu_24.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_alvistack.gpg > /dev/null
sudo -E apt-get update
sudo -E apt-get install -y ansible ansible-lint python3-docker python3-netaddr python3-vagrant
fi
sh -x -c "ansible --version"
sh -x -c "ansible-lint --version"
.script-bootstrap-molecule: &script-bootstrap-molecule
- |
if ! [[ -x "$(command -v molecule)" ]]; then
export DEBIAN_FRONTEND="noninteractive"
echo "deb http://downloadcontent.opensuse.org/repositories/home:/alvistack/xUbuntu_24.04/ /" | sudo tee /etc/apt/sources.list.d/home:alvistack.list
curl -fsSL https://downloadcontent.opensuse.org/repositories/home:alvistack/xUbuntu_24.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_alvistack.gpg > /dev/null
sudo -E apt-get update
sudo -E apt-get install -y python3-molecule python3-molecule-plugins
fi
sh -x -c "molecule --version"
.script-bootstrap-docker: &script-bootstrap-docker
- |
if ! [[ -x "$(command -v docker)" ]]; then
export DEBIAN_FRONTEND="noninteractive"
echo "deb http://downloadcontent.opensuse.org/repositories/home:/alvistack/xUbuntu_24.04/ /" | sudo tee /etc/apt/sources.list.d/home:alvistack.list
curl -fsSL https://downloadcontent.opensuse.org/repositories/home:alvistack/xUbuntu_24.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_alvistack.gpg > /dev/null
sudo -E apt-get update
sudo -E apt-get install -y crun podman podman-docker
fi
sh -x -c "docker --version"
.script-bootstrap-packer: &script-bootstrap-packer
- |
if ! [[ -x "$(command -v packer)" ]]; then
export DEBIAN_FRONTEND="noninteractive"
echo "deb http://downloadcontent.opensuse.org/repositories/home:/alvistack/xUbuntu_24.04/ /" | sudo tee /etc/apt/sources.list.d/home:alvistack.list
curl -fsSL https://downloadcontent.opensuse.org/repositories/home:alvistack/xUbuntu_24.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_alvistack.gpg > /dev/null
sudo -E apt-get update
sudo -E apt-get install -y packer packer-plugin-libvirt
fi
sh -x -c "packer --version"
.script-packer-build: &script-packer-build
- |
echo $DOCKER_HUB_TOKEN | sudo -E docker login --username=$DOCKER_HUB_USERNAME --password-stdin
cd $CI_PROJECT_DIR/packer/$_IMAGE-$_PROVIDER
sudo -E packer build packer.json
.script-docker-load: &script-docker-load
- |
zcat $CI_PROJECT_DIR/packer/$_IMAGE-$_PROVIDER/output-docker/image.tar.gz | sudo -E docker load
export _ORG="$CI_PROJECT_NAMESPACE"
export _ID="$(sudo -E docker images | awk '{ print $3 }' | awk 'NR==2')"
sudo -E docker tag $_ID $_ORG/$_IMAGE:latest
.script-molecule-test: &script-molecule-test
- |
export _MOLECULE_INSTANCE_NAME="$(pwgen -1AB 12)"
sudo -E molecule test -s $_IMAGE-$_PROVIDER
.script-docker-push: &script-docker-push
- |
if [[ -n "$CI_COMMIT_TAG" ]] && [[ "$CI_COMMIT_TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
export _TAG="$CI_COMMIT_TAG"
elif [[ -n "$CI_COMMIT_BRANCH" ]] && [[ "$CI_COMMIT_BRANCH" =~ master ]]; then
export _TAG="$(date +%Y%m%d).0.0"
else
exit 0
fi
echo $DOCKER_HUB_TOKEN | sudo -E docker login --username=$DOCKER_HUB_USERNAME --password-stdin
export _ORG="$CI_PROJECT_NAMESPACE"
export _ID="$(sudo -E docker images | awk '{ print $3 }' | awk 'NR==2')"
sudo -E docker tag $_ID $_ORG/$_IMAGE:latest
sudo -E docker push $_ORG/$_IMAGE:latest
sudo -E docker tag $_ID $_ORG/$_IMAGE:$_TAG
sudo -E docker push $_ORG/$_IMAGE:$_TAG
.job-packer-build: &job-packer-build
script:
- *script-bootstrap-python
- *script-bootstrap-ansible
- *script-bootstrap-docker
- *script-bootstrap-packer
- *script-packer-build
.job-molecule-test: &job-molecule-test
script:
- *script-bootstrap-python
- *script-bootstrap-ansible
- *script-bootstrap-molecule
- *script-bootstrap-docker
- *script-docker-load
- *script-molecule-test
.job-docker-push: &job-docker-push
script:
- *script-bootstrap-docker
- *script-docker-load
- *script-docker-push
default:
retry: 2
before_script:
- *script-git-submodule
- *script-linters
build:postfix-3.8-docker:
<<: *job-packer-build
stage: build
cache:
key: $CI_PIPELINE_ID-postfix-3.8-docker
paths:
- packer/*/output-docker
variables:
_IMAGE: postfix-3.8
_PROVIDER: docker
test:postfix-3.8-docker:
<<: *job-molecule-test
stage: test
cache:
key: $CI_PIPELINE_ID-postfix-3.8-docker
paths:
- packer/*/output-docker
policy: pull
variables:
_IMAGE: postfix-3.8
_PROVIDER: docker
needs:
- build:postfix-3.8-docker
deploy:postfix-3.8-docker:
<<: *job-docker-push
stage: deploy
cache:
key: $CI_PIPELINE_ID-postfix-3.8-docker
paths:
- packer/*/output-docker
policy: pull
variables:
_IMAGE: postfix-3.8
_PROVIDER: docker
needs:
- test:postfix-3.8-docker