-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy path00base_spec.rb
More file actions
376 lines (310 loc) · 11.4 KB
/
Copy path00base_spec.rb
File metadata and controls
376 lines (310 loc) · 11.4 KB
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
require 'spec_helper'
describe 'minimum2scp/baseimage-trixie' do
context 'without env' do
before(:all) do
start_container({
'Image' => ENV['DOCKER_IMAGE'] || "minimum2scp/#{File.basename(__dir__)}:latest",
})
end
after(:all) do
stop_container
end
## usr merge
## https://wiki.debian.org/UsrMerge
%w[/bin /lib /lib64 /sbin].each do |dir|
describe file(dir) do
it { should be_symlink }
it { should be_linked_to "usr#{dir}" }
end
end
describe file('/etc/apt/sources.list') do
apt_line_re = ->(enabled, type, uri, suite, *components) {
/^#{enabled ? '' : '#'}#{type}\s+#{Regexp.quote(uri)}\s+#{suite}\s+#{components.join('\s+')}$/
}
## trixie
its(:content) { should match apt_line_re[true, 'deb', 'http://deb.debian.org/debian/', 'trixie', 'main', 'contrib', 'non-free'] }
its(:content) { should match apt_line_re[true, 'deb-src', 'http://deb.debian.org/debian/', 'trixie', 'main', 'contrib', 'non-free'] }
its(:content) { should match apt_line_re[true, 'deb', 'http://security.debian.org/debian-security', 'trixie-security', 'main', 'contrib', 'non-free'] }
its(:content) { should match apt_line_re[true, 'deb-src', 'http://security.debian.org/debian-security', 'trixie-security', 'main', 'contrib', 'non-free'] }
end
describe file('/etc/apt/apt.conf.d/proxy.conf') do
it { should_not be_exist }
end
%w[
sudo adduser curl ca-certificates openssl git lv vim-tiny man-db whiptail zsh net-tools unzip bzip2 zstd
etckeeper locales tzdata localepurge sysvinit-core openssh-server rsyslog cron orphan-sysvinit-scripts tree
].each do |pkg|
describe package(pkg) do
it { should be_installed }
end
end
%w[
systemd systemd-sysv
].each do |pkg|
describe package(pkg) do
it { should_not be_installed }
end
end
describe file("/etc/default/locale") do
its(:content){ should include 'LANG=C' }
end
describe file("/etc/locale.gen") do
its(:content){ should match /^en_US\.UTF-8\s+UTF-8\s*/ }
its(:content){ should match /^ja_JP\.UTF-8\s+UTF-8\s*/ }
end
describe file("/etc/timezone") do
its(:content){ should include 'Asia/Tokyo' }
end
describe file("/etc/localtime") do
it { should be_linked_to '/usr/share/zoneinfo/Asia/Tokyo' }
end
describe file("/etc/locale.nopurge") do
its(:content){ should match /^en$/ }
its(:content){ should match /^en_US$/ }
its(:content){ should match /^en_US\.UTF-8$/ }
its(:content){ should match /^ja$/ }
its(:content){ should match /^ja_JP\.UTF-8$/ }
end
describe file("/etc/inittab") do
its(:content) { should match %r!^#si::sysinit:/etc/init.d/rcS! }
its(:content) { should match %r!^#1:2345:respawn:/sbin/getty --noclear 38400 tty1$! }
its(:content) { should match %r!^#[2-6]:23:respawn:/sbin/getty 38400 tty[2-6]$! }
end
describe file("/etc/sudoers") do
it { should be_mode 440 }
its(:content) { should match /^#%sudo\s+/ }
end
describe file("/etc/sudoers.d/local") do
it { should be_mode 440 }
its(:content) { should include '%sudo ALL=(ALL:ALL) NOPASSWD: ALL' }
end
describe group('debian') do
it { should be_exist }
it { should have_gid 2000 }
end
describe user('debian') do
it { should be_exist }
it { should belong_to_group 'debian' }
it { should belong_to_group 'sudo' }
it { should belong_to_group 'adm' }
it { should have_uid 2000 }
it { should have_home_directory '/home/debian' }
it { should have_login_shell '/bin/bash' }
end
%w[ssh cron rsyslog].each do |svc|
describe service(svc) do
it { should be_enabled }
it { should be_running }
end
end
describe file('/opt/init-wrapper') do
it { should be_directory }
end
describe file('/opt/init-wrapper/sbin') do
it { should be_directory }
end
describe file('/opt/init-wrapper/sbin/entrypoint.sh') do
it { should be_executable }
end
describe file('/opt/init-wrapper/post-init.d') do
it { should be_directory }
end
describe file('/opt/init-wrapper/pre-init.d') do
it { should be_directory }
end
describe file('/opt/init-wrapper/pre-init.d/01-git-config') do
it { should be_executable }
end
describe file('/opt/init-wrapper/pre-init.d/02-reset-sshd-keys') do
it { should be_executable }
end
describe file('/opt/init-wrapper/pre-init.d/03-adduser') do
it { should be_executable }
end
describe file('/opt/init-wrapper/pre-init.d/04-chpass-and-sshkey') do
it { should be_executable }
end
describe file('/opt/init-wrapper/pre-init.d/05-apt') do
it { should be_executable }
end
describe file('/opt/init-wrapper/pre-init.d/06-remove-unnecessary-files') do
it { should be_executable }
end
describe file('/opt/init-wrapper/pre-init.d/10-save-env') do
it { should be_executable }
end
describe file('/tmp/build') do
it { should_not be_directory }
end
describe command('etckeeper vcs config get gc.auto') do
its(:stdout){ should eq "0\n" }
its(:stderr){ should eq "" }
its(:exit_status){ should eq 0 }
end
end
context 'with env [APT_LINE=jp APT_HTTP_PROXY=http://x.x.x.x:3142/ DEFAULT_LANG=en_US.UTF-8, DEFAULT_TZ=UTC]' do
before(:all) do
start_container({
'Image' => ENV['DOCKER_IMAGE'] || "minimum2scp/#{File.basename(__dir__)}:latest",
'Env' => [ 'APT_LINE=jp', 'APT_HTTP_PROXY=http://x.x.x.x:3142/', 'DEFAULT_LANG=en_US.UTF-8', 'DEFAULT_TZ=UTC' ]
})
end
after(:all) do
stop_container
end
describe file('/etc/apt/sources.list') do
apt_line_re = ->(enabled, type, uri, suite, *components) {
/^#{enabled ? '' : '#'}#{type}\s+#{Regexp.quote(uri)}\s+#{suite}\s+#{components.join('\s+')}$/
}
## trixie
its(:content) { should match apt_line_re[true, 'deb', 'http://ftp.jp.debian.org/debian/', 'trixie', 'main', 'contrib', 'non-free'] }
its(:content) { should match apt_line_re[true, 'deb-src', 'http://ftp.jp.debian.org/debian/', 'trixie', 'main', 'contrib', 'non-free'] }
its(:content) { should match apt_line_re[true, 'deb', 'http://security.debian.org/debian-security', 'trixie-security', 'main', 'contrib', 'non-free'] }
its(:content) { should match apt_line_re[true, 'deb-src', 'http://security.debian.org/debian-security', 'trixie-security', 'main', 'contrib', 'non-free'] }
end
describe file('/etc/apt/apt.conf.d/proxy.conf') do
it { should be_exist }
its(:content){ should include 'Acquire::http::proxy "http://x.x.x.x:3142/";' }
its(:content){ should include 'Acquire::https::proxy "DIRECT";' }
end
describe file("/etc/default/locale") do
its(:content){ should include 'LANG=en_US.UTF-8' }
end
describe file("/etc/timezone") do
its(:content){ should include 'Etc/UTC' }
end
describe file("/etc/localtime") do
it { should be_linked_to '/usr/share/zoneinfo/Etc/UTC' }
end
end
context 'with env [CUSTOM_USER=testuser]' do
before(:all) do
start_container({
'Image' => ENV['DOCKER_IMAGE'] || "minimum2scp/#{File.basename(__dir__)}:latest",
'Env' => [ 'CUSTOM_USER=testuser' ]
})
end
after(:all) do
stop_container
end
describe group('testuser') do
it { should exist }
end
describe user('testuser') do
it { should exist }
it { should belong_to_group('testuser') }
it { should have_login_shell '/bin/bash' }
end
end
context 'with env [CUSTOM_USER=testuser, CUSTOM_USER_UID=1999, CUSTOM_USER_SHELL=/bin/false, CUSTOM_GROUP=testgrp, CUSTOM_GROUP_GID=1999]' do
before(:all) do
start_container({
'Image' => ENV['DOCKER_IMAGE'] || "minimum2scp/#{File.basename(__dir__)}:latest",
'Env' => [
'CUSTOM_USER=testuser',
'CUSTOM_USER_UID=1999',
'CUSTOM_USER_SHELL=/bin/false',
'CUSTOM_GROUP=testgrp',
'CUSTOM_GROUP_GID=1999',
]
})
end
after(:all) do
stop_container
end
describe group('testgrp') do
it { should exist }
it { should have_gid 1999 }
end
describe user('testuser') do
it { should exist }
it { should belong_to_group('testgrp') }
it { should have_login_shell '/bin/false' }
it { should have_uid 1999 }
end
end
context 'with env [INSTALL_DOCKER_CE_CLI=yes]' do
before(:all) do
start_container({
'Image' => ENV['DOCKER_IMAGE'] || "minimum2scp/#{File.basename(__dir__)}:latest",
'Env' => [ 'INSTALL_DOCKER_CE_CLI=yes' ]
})
# wait /opt/init-wrapper/post-init.d/07-docker-ce-cli
wait_container_file('/usr/local/bin/docker')
end
after(:all) do
stop_container
end
describe file('/opt/init-wrapper/post-init.d/07-docker-ce-cli') do
it { should be_executable }
end
describe file('/usr/local/bin/docker') do
it { should be_executable }
end
describe command('docker --version') do
its(:stdout){ should start_with('Docker version 28.5.1, ') }
end
end
context 'with env [INSTALL_NGINX=yes]' do
before(:all) do
start_container({
'Image' => ENV['DOCKER_IMAGE'] || "minimum2scp/#{File.basename(__dir__)}:latest",
'Env' => [ 'INSTALL_NGINX=yes' ]
})
# wait for nignx in container start
wait_container_port(80)
end
after(:all) do
stop_container
end
describe file('/opt/init-wrapper/post-init.d/07-nginx') do
it { should be_executable }
end
describe file('/etc/apt/sources.list.d/nginx.list') do
it {
pending 'Switched nginx package to debian.org ones'
should be_file
}
end
describe file('/usr/share/keyrings/nginx.gpg') do
it {
pending 'Switched nginx package to debian.org ones'
should be_file
}
end
describe file('/etc/apt/preferences.d/nginx') do
it {
pending 'Switched nginx package to debian.org ones'
should be_file
}
end
describe command('apt-cache policy') do
its(:stdout) {
pending 'Switched nginx package to debian.org ones'
should include " 600 http://nginx.org/packages/mainline/debian bullseye/nginx amd64 Packages\n" +
" release v=11.0,o=nginx,a=stable,n=bullseye,l=nginx,c=nginx,b=amd64\n" +
" origin nginx.org\n"
}
its(:stdout) {
pending 'Switched nginx package to debian.org ones'
should include " 600 http://nginx.org/packages/debian bullseye/nginx amd64 Packages\n" +
" release v=11.0,o=nginx,a=stable,n=bullseye,l=nginx,c=nginx,b=amd64\n" +
" origin nginx.org\n"
}
end
describe package('nginx') do
it {
pending 'Switched nginx package to debian.org ones'
should be_installed.with_version('1.22.1-1~bullseye')
}
it { should be_installed.with_version('1.26.3-3+deb13u5') }
end
describe file('/etc/nginx/conf.d/misc.conf') do
it { should be_file }
end
describe service('nginx') do
it { should be_running }
it { should be_enabled }
end
end
end