Skip to content

Commit 168a2f1

Browse files
author
underpost.net
committed
ci(package-pwa-microservices-template-ghpkg): ⚙️ Update github repo package
1 parent b1851d0 commit 168a2f1

File tree

8 files changed

+137
-66
lines changed

8 files changed

+137
-66
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Run dev client server
6868
npm run dev
6969
```
7070
<!-- -->
71-
## underpost ci/cd cli v2.8.816
71+
## underpost ci/cd cli v2.8.817
7272

7373
### Usage: `underpost [options] [command]`
7474
```

bin/deploy.js

Lines changed: 128 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ const keyboardSteps = [
6969
`sudo dpkg-reconfigure --frontend noninteractive keyboard-configuration`,
7070
`sudo systemctl restart keyboard-setup.service`,
7171
];
72-
// # - ${JSON.stringify([...timeZoneSteps, ...chronySetUp(chronyConfPath)])}
72+
73+
const kernelLibVersion = `6.8.0-41-generic`;
74+
7375
const installSteps = [
7476
`cat <<EOF | tee /etc/apt/sources.list
7577
deb http://ports.ubuntu.com/ubuntu-ports noble main restricted universe multiverse
@@ -79,7 +81,11 @@ EOF`,
7981

8082
`apt update -qq`,
8183
`apt -y full-upgrade`,
82-
`apt install -y xinput x11-xkb-utils usbutils`,
84+
`apt install -y build-essential xinput x11-xkb-utils usbutils`,
85+
'apt install -y linux-image-generic',
86+
`apt install -y linux-modules-${kernelLibVersion} linux-modules-extra-${kernelLibVersion}`,
87+
88+
`depmod -a ${kernelLibVersion}`,
8389
// `apt install -y cloud-init=25.1.2-0ubuntu0~24.04.1`,
8490
`apt install -y cloud-init systemd-sysv openssh-server sudo locales udev util-linux systemd-sysv iproute2 netplan.io ca-certificates curl wget chrony`,
8591
`ln -sf /lib/systemd/systemd /sbin/init`,
@@ -89,12 +95,31 @@ EOF`,
8995
`DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata kmod keyboard-configuration console-setup iputils-ping`,
9096
];
9197

98+
const bootCmdSteps = [
99+
`/underpost/dns.sh`,
100+
`/underpost/host.sh`,
101+
// `/underpost/date.sh`,
102+
`cp -a /underpost/90_maas.cfg /etc/cloud/cloud.cfg.d/90_maas.cfg`,
103+
];
104+
105+
const cloudInitReset = `sudo cloud-init clean --logs --seed --configs all --machine-id
106+
sudo rm -rf /var/lib/cloud/*`;
107+
108+
const cloudConfigCmdRunFactory = (steps = []) =>
109+
steps
110+
.map(
111+
(step, i, a) =>
112+
' - echo "\\$(date) | ' + (i + 1) + '/' + a.length + ' - ' + step.split('\n')[0] + '"' + `\n` + ` - ${step}`,
113+
)
114+
.join('\n');
115+
92116
const cloudConfigFactory = (
93-
{ IP_ADDRESS, architecture, host, nfsHostPath, ipaddr, update, gatewayip },
117+
{ IP_ADDRESS, architecture, host, nfsHostPath, ipaddr, update, gatewayip, reset },
94118
{ consumer_key, consumer_secret, token_key, token_secret },
119+
path = '/etc/cloud/cloud.cfg.d/90_maas.cfg',
95120
) => [
96121
// Configure cloud-init for MAAS
97-
`cat <<EOF_MAAS_CFG > /etc/cloud/cloud.cfg.d/90_maas.cfg
122+
`cat <<EOF_MAAS_CFG > ${path}
98123
#cloud-config
99124
100125
hostname: ${host}
@@ -114,7 +139,7 @@ datasource:
114139
MAAS:
115140
metadata_url: http://${IP_ADDRESS}:5240/MAAS/metadata/
116141
${
117-
process.argv.includes('reset')
142+
reset
118143
? ''
119144
: `consumer_key: ${consumer_key}
120145
consumer_secret: ${consumer_secret}
@@ -142,18 +167,15 @@ users:
142167
143168
# check timedatectl on host
144169
# timezone: America/Santiago
145-
# timezone: ${timezone}
170+
timezone: ${timezone}
146171
147172
ntp:
148173
enabled: true
149174
servers:
150175
- ${process.env.MAAS_NTP_SERVER}
151176
ntp_client: chrony
152-
# config:
153-
# confpath: ${chronyConfPath}
154-
# packages:
155-
# - chrony
156-
# service_name: chrony
177+
config:
178+
confpath: ${chronyConfPath}
157179
158180
# ssh:
159181
# allow-pw: false
@@ -167,9 +189,10 @@ packages:
167189
- git
168190
- htop
169191
- snapd
192+
- chrony
170193
resize_rootfs: false
171194
growpart:
172-
mode: off
195+
mode: false
173196
network:
174197
version: 2
175198
ethernets:
@@ -186,7 +209,7 @@ network:
186209
# users:
187210
# - {name: root, password: changeme, type: text}
188211
189-
final_message: "The system is up, after $UPTIME seconds"
212+
final_message: "====== Cloud init finished ======"
190213
191214
# power_state:
192215
# mode: reboot
@@ -197,6 +220,7 @@ bootcmd:
197220
- echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
198221
- echo "Init bootcmd"
199222
- echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
223+
${cloudConfigCmdRunFactory(bootCmdSteps)}
200224
runcmd:
201225
- echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
202226
- echo "Init runcmd"
@@ -212,61 +236,37 @@ preserve_hostname: false
212236
# The modules that run in the 'init' stage
213237
cloud_init_modules:
214238
- migrator
215-
- seed_random
216239
- bootcmd
217240
- write-files
218241
- growpart
219242
- resizefs
220-
- disk_setup
221-
- mounts
222243
- set_hostname
223-
- update_hostname
224244
- update_etc_hosts
225-
- ca-certs
226245
- rsyslog
227246
- users-groups
228247
- ssh
229248
230-
# The modules that run in the 'config' stage
231249
cloud_config_modules:
232-
# Emit the cloud config ready event
233-
# this can be used by upstart jobs for 'start on cloud-config'.
234-
- emit_upstart
235-
- snap_config
236-
- ssh-import-id
250+
- mounts
237251
- locale
238252
- set-passwords
239-
- grub-dpkg
240-
- apt-pipelining
241-
- apt-configure
242-
- ntp
253+
- package-update-upgrade-install
243254
- timezone
244-
- disable-ec2-metadata
245255
- runcmd
246-
- byobu
256+
- ssh-import-id
257+
- ntp
247258
248-
# The modules that run in the 'final' stage
249259
cloud_final_modules:
250-
- snappy
251-
- package-update-upgrade-install
252-
# - fan
253-
# - landscape
254-
# - lxd
255-
# - puppet
256-
- chef
257-
- salt-minion
258-
- mcollective
259260
- rightscale_userdata
260-
- scripts-vendor
261261
- scripts-per-once
262262
- scripts-per-boot
263263
- scripts-per-instance
264264
- scripts-user
265265
- ssh-authkey-fingerprints
266266
- keys-to-console
267-
# - phone-home
267+
- phone-home
268268
- final-message
269-
# - power-state-change
269+
270270
EOF_MAAS_CFG`,
271271
];
272272

@@ -285,7 +285,9 @@ EOF_OUTER`;
285285
shellExec(cmd);
286286
};
287287

288-
const chronySetUp = (path) => {
288+
const chronySetUp = (path, alias = 'chrony') => {
289+
// use alias = 'chronyd' for RHEL
290+
// use alias = 'chrony' for Ubuntu
289291
return [
290292
`echo '
291293
# Use public servers from the pool.ntp.org project.
@@ -328,25 +330,25 @@ logdir /var/log/chrony
328330
# Select which information is logged.
329331
#log measurements statistics tracking
330332
' > ${path} `,
331-
`sudo systemctl stop chronyd`,
333+
`systemctl stop ${alias}`,
334+
335+
`${alias}d -q 'server ntp.ubuntu.com iburst'`,
332336

333337
// `chronyd -q 'server 0.europe.pool.ntp.org iburst'`,
334-
`chronyd -q 'server ntp.ubuntu.com iburst'`,
335338

336-
`sudo systemctl enable --now chronyd`,
337-
`sudo systemctl restart chronyd`,
338-
`sudo systemctl status chronyd`,
339+
`sudo systemctl enable --now ${alias}`,
340+
`sudo systemctl restart ${alias}`,
341+
`sudo systemctl status ${alias}`,
339342

340343
`chronyc sources`,
341344
`chronyc tracking`,
342-
// sudo firewall-cmd --add-service=ntp --permanent
343-
// sudo firewall-cmd --reload
344345

345346
`chronyc sourcestats -v`,
347+
`timedatectl status`,
346348
];
347349
};
348350

349-
const installUbuntuUnderpostTools = (nfsHostPath) => {
351+
const installUbuntuUnderpostTools = ({ nfsHostPath, host }) => {
350352
fs.mkdirSync(`${nfsHostPath}/underpost`, { recursive: true });
351353

352354
logger.info('Build', `${nfsHostPath}/underpost/date.sh`);
@@ -358,6 +360,20 @@ ${chronySetUp(chronyConfPath).join('\n')}
358360
'utf8',
359361
);
360362

363+
logger.info('Build', `${nfsHostPath}/underpost/host.sh`);
364+
fs.writeFileSync(
365+
`${nfsHostPath}/underpost/host.sh`,
366+
`echo -e "127.0.0.1 localhost\n127.0.1.1 ${host}" | tee -a /etc/hosts`,
367+
'utf8',
368+
);
369+
370+
logger.info('Build', `${nfsHostPath}/underpost/keys.sh`);
371+
fs.writeFileSync(
372+
`${nfsHostPath}/underpost/keys.sh`,
373+
`cat /etc/cloud/cloud.cfg.d/90_maas.cfg | grep -C 5 'metadata'`,
374+
'utf8',
375+
);
376+
361377
logger.info('Build', `${nfsHostPath}/underpost/keyboard.sh`);
362378
fs.writeFileSync(
363379
`${nfsHostPath}/underpost/keyboard.sh`,
@@ -376,6 +392,24 @@ ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf`,
376392
'utf8',
377393
);
378394

395+
logger.info('Build', `${nfsHostPath}/underpost/start.sh`);
396+
fs.writeFileSync(
397+
`${nfsHostPath}/underpost/start.sh`,
398+
`#!/bin/bash
399+
set -x
400+
sudo cloud-init --all-stages
401+
`,
402+
'utf8',
403+
);
404+
405+
logger.info('Build', `${nfsHostPath}/underpost/reset.sh`);
406+
fs.writeFileSync(
407+
`${nfsHostPath}/underpost/reset.sh`,
408+
`${cloudInitReset}
409+
${bootCmdSteps.join('\n')}`,
410+
'utf8',
411+
);
412+
379413
logger.info('Build', `${nfsHostPath}/underpost/help.sh`);
380414
fs.writeFileSync(
381415
`${nfsHostPath}/underpost/help.sh`,
@@ -417,7 +451,12 @@ cut -d: -f1 /etc/passwd
417451
`chmod +x /underpost/dns.sh`,
418452
`chmod +x /underpost/help.sh`,
419453
`chmod +x /underpost/config-path.sh`,
454+
`chmod +x /underpost/host.sh`,
455+
`chmod +x /underpost/keys.sh`,
420456
`chmod +x /underpost/test.sh`,
457+
`chmod +x /underpost/start.sh`,
458+
`chmod +x /underpost/reset.sh`,
459+
chronySetUp(chronyConfPath)[0],
421460
`sudo chmod 700 ~/.ssh/`,
422461
`sudo chmod 600 ~/.ssh/authorized_keys`,
423462
`sudo chmod 644 ~/.ssh/known_hosts`,
@@ -461,8 +500,7 @@ const updateVirtualRoot = async ({ IP_ADDRESS, architecture, host, nfsHostPath,
461500
// --reboot
462501
if (process.argv.includes('reset'))
463502
shellExec(`sudo chroot ${nfsHostPath} /usr/bin/qemu-aarch64-static /bin/bash <<'EOF'
464-
sudo cloud-init clean --logs --seed --configs all --machine-id
465-
sudo rm -rf /var/lib/cloud/*
503+
${cloudInitReset}
466504
EOF`);
467505

468506
if (fs.existsSync(`${nfsHostPath}/var/log/`)) {
@@ -495,11 +533,38 @@ EOF`);
495533
runSteps(
496534
nfsHostPath,
497535
cloudConfigFactory(
498-
{ IP_ADDRESS, architecture, host, nfsHostPath, ipaddr, update, gatewayip },
536+
{
537+
reset: process.argv.includes('reset') ? true : false,
538+
IP_ADDRESS,
539+
architecture,
540+
host,
541+
nfsHostPath,
542+
ipaddr,
543+
update,
544+
gatewayip,
545+
},
546+
{ consumer_key, consumer_secret, token_key, token_secret },
547+
),
548+
);
549+
550+
runSteps(
551+
nfsHostPath,
552+
cloudConfigFactory(
553+
{
554+
IP_ADDRESS,
555+
architecture,
556+
host,
557+
nfsHostPath,
558+
ipaddr,
559+
update,
560+
gatewayip,
561+
},
499562
{ consumer_key, consumer_secret, token_key, token_secret },
563+
'/underpost/90_maas.cfg',
500564
),
501565
);
502-
installUbuntuUnderpostTools(nfsHostPath);
566+
567+
installUbuntuUnderpostTools({ nfsHostPath, host });
503568
};
504569

505570
try {
@@ -2022,6 +2087,7 @@ EOF`);
20222087
];
20232088
const cmd = [
20242089
`console=serial0,115200`,
2090+
// `console=ttyAMA0,115200`,
20252091
`console=tty1`,
20262092
// `initrd=-1`,
20272093
// `net.ifnames=0`,
@@ -2045,6 +2111,12 @@ EOF`);
20452111
// 'ip=dfcp',
20462112
// 'autoinstall',
20472113
// 'rd.break',
2114+
2115+
// Disable services that not apply over nfs
2116+
`systemd.mask=systemd-network-generator.service`,
2117+
`systemd.mask=systemd-networkd.service`,
2118+
`systemd.mask=systemd-fsck-root.service`,
2119+
`systemd.mask=systemd-udev-trigger.service`,
20482120
];
20492121

20502122
// TODO: use autoinstall cloud-config-url=http://<MAAS_IP>:5240/MAAS/metadata/latest
@@ -2392,7 +2464,6 @@ udp-port = 32766
23922464
shellExec(`sudo mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc`);
23932465

23942466
if (process.argv.includes('build')) {
2395-
// shellExec(`depmod -a`);
23962467
shellExec(`mkdir -p ${nfsHostPath}`);
23972468
let cmd;
23982469
switch (host) {

cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## underpost ci/cd cli v2.8.816
1+
## underpost ci/cd cli v2.8.817
22

33
### Usage: `underpost [options] [command]`
44
```

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ services:
5858
cpus: '0.25'
5959
memory: 20M
6060
labels: # labels in Compose file instead of Dockerfile
61-
engine.version: '2.8.816'
61+
engine.version: '2.8.817'
6262
networks:
6363
- load-balancer
6464

0 commit comments

Comments
 (0)