Skip to content

Commit 335ea4d

Browse files
authored
Merge pull request #222 from yfyf/release/2023.9.1-DISK
Backport release disk to 2023.9.1
2 parents a995866 + 6e93efe commit 335ea4d

File tree

10 files changed

+222
-9
lines changed

10 files changed

+222
-9
lines changed
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
RELEASE_TAG="$1"
5+
6+
# Find the previous "proper" release (i.e. not VALIDATION) tag.
7+
# Note: `--version-sort` incorrectly sorts semver pre-releases, but
8+
# these get filtered out later, so it does not matter.
9+
prev_tag="$(git tag \
10+
| sort --version-sort \
11+
| grep -B10000 "$RELEASE_TAG" \
12+
| grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' \
13+
| head -n -1 \
14+
| tail -1)" || echo ""
15+
16+
if [[ -z "$prev_tag" ]]; then
17+
echo "Error: failed to determine previous release tag, are you sure input tag $RELEASE_TAG exists?"
18+
exit 1
19+
else
20+
echo "Previous proper release tag is: $prev_tag" >&2
21+
fi
22+
23+
echo -e "
24+
# Release $RELEASE_TAG
25+
26+
## Artifacts
27+
28+
- Test disk: [https://dividat-playos-test-disks.s3.amazonaws.com/by-tag/playos-release-disk-$RELEASE_TAG.img.zst](https://dividat-playos-test-disks.s3.amazonaws.com/by-tag/playos-release-disk-$RELEASE_TAG.img.zst)
29+
30+
## Changelog
31+
32+
"
33+
34+
# print changelog since $prev_tag (exclusive)
35+
grep -E -B10000 "^# \[$prev_tag\]" ./Changelog.md \
36+
| head -n -1 \
37+
| sed -E 's/#+/\0##/'

.github/workflows/release-tag.yml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Release Tag
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
fetch-tags: true
20+
21+
- name: Ensure KVM is usable by nix-build
22+
run: sudo chmod a+rwx /dev/kvm
23+
shell: bash
24+
- uses: cachix/install-nix-action@v18
25+
with:
26+
nix_path: nixpkgs=channel:nixos-unstable
27+
extra_nix_config: |
28+
system-features = nixos-test benchmark big-parallel kvm
29+
- uses: DeterminateSystems/magic-nix-cache-action@v8
30+
31+
- name: Make magic-nix-cache read-only by removing post-build-hook
32+
run: sed -i '/post-build-hook = magic-nix-cache-build-hook/d' $HOME/.config/nix/nix.conf
33+
34+
- name: Validate tag
35+
run: |
36+
app_vsn="$(nix eval --raw -f application.nix 'version')"
37+
if [ "$app_vsn" != "$GITHUB_REF_NAME" ]; then
38+
echo "Git tag ($GITHUB_REF_NAME) does not match version in application.nix ($app_vsn), aborting!"
39+
exit 1
40+
fi
41+
42+
- name: Build release disk
43+
run: ./build release-disk
44+
45+
- name: Configure AWS credentials
46+
uses: aws-actions/configure-aws-credentials@v3
47+
with:
48+
aws-access-key-id: ${{ secrets.TEST_DISKS_ACCESS_KEY_ID }}
49+
aws-secret-access-key: ${{ secrets.TEST_DISKS_SECRET_ACCESS_KEY }}
50+
aws-region: eu-central-1
51+
52+
- name: Publish to S3
53+
run: ./.github/workflows/upload-test-disk.sh "$GITHUB_REF_NAME"
54+
55+
- name: Create Release summary
56+
run: ./.github/workflows/gen-release-summary.sh "$GITHUB_REF_NAME" > ./release-notes.md
57+
58+
- name: Create Release
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
run: |
62+
extra_args=""
63+
if [[ "$GITHUB_REF_NAME" == *VALIDATION ]]; then
64+
extra_args="--prerelease"
65+
elif [[ "$GITHUB_REF_NAME" == *TEST ]]; then
66+
extra_args="--draft"
67+
fi
68+
69+
gh release create --verify-tag \
70+
-F ./release-notes.md \
71+
$extra_args \
72+
"$GITHUB_REF_NAME"

.github/workflows/upload-test-disk.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
RELEASE_TAG="$1"
4+
5+
set -euo pipefail
6+
set -x
7+
disk_path="$(readlink ./result/playos-release-disk-$RELEASE_TAG.img.zst)"
8+
target_url="s3://dividat-playos-test-disks/by-tag/playos-release-disk-$RELEASE_TAG.img.zst"
9+
echo "Uploading test disk to: $target_url"
10+
aws s3 cp "$disk_path" "$target_url"

application.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
rec {
22
fullProductName = "Dividat PlayOS";
33
safeProductName = "playos";
4-
version = "2023.9.1";
4+
version = "2023.9.1-DISK";
55

66
greeting = label: ''
77
_

build

+21
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,27 @@ elif [ "$TARGET" == "shed-key" ]; then
9999
--arg buildBundle false \
100100
--arg buildDisk false)
101101

102+
# builds a disk to be used as a base image in ./testing/release-validation.nix
103+
elif [ "$TARGET" == "release-disk" ]; then
104+
105+
echo -e "
106+
Building release disk image for release validation tests.
107+
108+
Note: requires around 30GiB of free space for storing the intermediate disk
109+
images. The final compressed disk image is much smaller (~4 GiB).
110+
"
111+
112+
(set -x; nix-build \
113+
--arg kioskUrl "http://kiosk-server.local/" \
114+
--arg updateUrl "http://update-server.local/" \
115+
--arg buildVm false \
116+
--arg buildInstaller false \
117+
--arg buildBundle false \
118+
--arg buildLive false \
119+
--arg buildDisk false \
120+
--arg buildReleaseDisk true
121+
)
122+
102123
elif [ "$TARGET" == "default" ]; then
103124

104125
(set -x; nix-build)

default.nix

+25-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ in
2020
, buildInstaller ? true
2121
, buildBundle ? true
2222
, buildDisk ? true
23+
, buildReleaseDisk ? false
2324
, buildLive ? true
2425
}:
2526

@@ -31,8 +32,9 @@ let
3132
applicationOverlays = application.overlays;
3233
});
3334

34-
# lib.makeScope returns consistent set of packages that depend on each other (and is my new favorite nixpkgs trick)
35-
components = with pkgs; lib.makeScope newScope (self: with self; {
35+
# lib.makeScope returns consistent set of packages that depend on each other
36+
mkComponents = { application, extraModules ? [ ], rescueSystemOpts ? {}, diskBuildEnabled ? buildDisk }:
37+
(with pkgs; lib.makeScope newScope (self: with self; {
3638

3739
inherit updateUrl deployUrl kioskUrl;
3840
inherit (application) version safeProductName fullProductName;
@@ -55,7 +57,10 @@ let
5557
updateCert = copyPathToStore updateCert;
5658

5759
# System image as used in full installation
58-
systemImage = callPackage ./system-image { application = application; };
60+
systemImage = callPackage ./system-image {
61+
application = application;
62+
extraModules = extraModules;
63+
};
5964

6065
# USB live system
6166
live = callPackage ./live { application = application; };
@@ -86,8 +91,18 @@ let
8691
# Script for spinning up VMs
8792
run-in-vm = callPackage ./testing/run-in-vm {};
8893

89-
});
94+
}));
95+
96+
components = mkComponents { inherit application; };
9097

98+
releaseDiskComponents = mkComponents {
99+
inherit application;
100+
extraModules = [ ./testing/system/passwordless-root.nix ];
101+
};
102+
103+
releaseDisk = pkgs.callPackage ./testing/disk/release.nix {
104+
inherit (releaseDiskComponents) install-playos;
105+
};
91106
in
92107

93108
with pkgs; stdenv.mkDerivation {
@@ -115,6 +130,12 @@ with pkgs; stdenv.mkDerivation {
115130
+ lib.optionalString buildLive ''
116131
ln -s ${components.live}/iso/${components.safeProductName}-live-${components.version}.iso $out/${components.safeProductName}-live-${components.version}.iso
117132
''
133+
+ lib.optionalString buildDisk ''
134+
ln -s ${components.disk} $out/${components.safeProductName}-disk-${components.version}.img
135+
''
136+
+ lib.optionalString buildReleaseDisk ''
137+
ln -s ${releaseDisk} $out/${components.safeProductName}-release-disk-${components.version}.img.zst
138+
''
118139
# Installer ISO image
119140
+ lib.optionalString buildInstaller ''
120141
ln -s ${components.installer}/iso/${components.safeProductName}-installer-${components.version}.iso $out/${components.safeProductName}-installer-${components.version}.iso

installer/install-playos/install-playos.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import re
1313
from datetime import datetime
1414

15-
PARTITION_SIZE_GB_SYSTEM = 10
16-
PARTITION_SIZE_GB_DATA = 5
15+
PARTITION_SIZE_GB_SYSTEM = 9
16+
PARTITION_SIZE_GB_DATA = 1
1717

1818
GRUB_CFG = "@grubCfg@"
1919
GRUB_ENV = '/mnt/boot/grub/grubenv'

system-image/default.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build an installable system image assuming a disk layout of a full A/B installation
2-
{pkgs, lib, updateCert, kioskUrl, playos-controller, application }:
2+
{pkgs, lib, updateCert, kioskUrl, playos-controller, application, extraModules ? [ ] }:
33
with lib;
44
let nixos = pkgs.importFromNixos ""; in
55
(nixos {
@@ -13,7 +13,7 @@ let nixos = pkgs.importFromNixos ""; in
1313

1414
# Application-specific module
1515
application.module
16-
];
16+
] ++ extraModules;
1717

1818
# Storage
1919
fileSystems = {

testing/disk/release.nix

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Similarly to testing/disk/default.nix, this builds a disk image containing
2+
# a full PlayOS installation, with these differences:
3+
# - It uses default system and boot partition sizes. Total disk size is ~20 GiB
4+
# - It produces a (sparsified) qcow2 image rather than a raw one. This reduces
5+
# the image size to ~8GiB
6+
# - It compresses the final image using zstd to reduce disk usage.
7+
# Final compressed file size is around ~4GiB.
8+
{ pkgs
9+
, lib
10+
, install-playos
11+
}:
12+
with pkgs;
13+
with lib;
14+
let
15+
# all sizes in MiB
16+
partSizes = {
17+
boot = 525; # 525 MiB (matches install-playos default)
18+
system = 1024 * 9; # 9 GiB (install-playos default - 1GiB)
19+
data = 400; # 400 MiB (same as testing/disk/default.nix)
20+
};
21+
diskSizeMiB = 8 + partSizes."boot" + partSizes."data" + (partSizes."system" * 2) + 1;
22+
in
23+
vmTools.runInLinuxVM (
24+
runCommand "build-playos-release-disk"
25+
{
26+
buildInputs = [install-playos];
27+
28+
preVM = ''
29+
diskImage=nixos.raw
30+
truncate -s ${toString diskSizeMiB}MiB $diskImage
31+
'';
32+
33+
postVM = ''
34+
mkdir -p $out
35+
${pkgs.qemu}/bin/qemu-img convert -f raw -O qcow2 $diskImage $out/playos-disk.img
36+
rm $diskImage
37+
${pkgs.zstd}/bin/zstd --rm -f $out/playos-disk.img -o $out/playos-disk.img.zst
38+
diskImage=$out/playos-disk.img.zst
39+
'';
40+
memSize = 1024;
41+
}
42+
''
43+
# machine-id of development image is hardcoded.
44+
install-playos \
45+
--device /dev/vda \
46+
--machine-id "f414cca8312548d29689ebf287fb67e0" \
47+
--no-confirm
48+
''
49+
) + "/playos-disk.img.zst"

testing/system/passwordless-root.nix

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
users.users.root.initialHashedPassword = "";
3+
}

0 commit comments

Comments
 (0)