Skip to content

Commit cf8a0e1

Browse files
authored
Consolidate build scripts (elementary#286)
* make sure all scripts exit on failure. * move all terraform script tooling into the build script. Add a new option to allow config to choose whether or not to include the appcenter ppa. * clean up comments related to old terraform script * remove artifacts dir step, direct output to builds/amd64. * move comments to better locations for logging * allow for uploading other arch types in the future * remove builds dir before moving over new builds * Remove the builds directory before all build runs instead of before each.
1 parent 5c692ff commit cf8a0e1

17 files changed

+115
-136
lines changed

.github/workflows/daily-5.1.yml

-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ jobs:
2222

2323
- name: Build and upload daily .iso
2424
run: |
25-
mkdir /artifacts
2625
./workflows.sh etc/terraform-daily-5.1-azure.conf "${{ secrets.key }}" "${{ secrets.secret }}" "${{ secrets.endpoint }}" "${{ secrets.bucket }}"

.github/workflows/daily-6.0.yml

-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ jobs:
2222

2323
- name: Build and upload daily .iso
2424
run: |
25-
mkdir /artifacts
2625
./workflows.sh etc/terraform-daily-6.0-azure.conf "${{ secrets.key }}" "${{ secrets.secret }}" "${{ secrets.endpoint }}" "${{ secrets.bucket }}"

.github/workflows/distinst-weekly.yml

-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ jobs:
1919

2020
- name: Build and upload distinst .iso
2121
run: |
22-
mkdir /artifacts
2322
./workflows.sh etc/terraform-daily-distinst-azure.conf "${{ secrets.key }}" "${{ secrets.secret }}" "${{ secrets.endpoint }}" "${{ secrets.bucket }}"

.github/workflows/stable.yml

-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ jobs:
2020

2121
- name: Build and upload stable .iso
2222
run: |
23-
mkdir /artifacts
2423
./workflows.sh etc/terraform-stable-azure.conf "${{ secrets.key }}" "${{ secrets.secret }}" "${{ secrets.endpoint }}" "${{ secrets.bucket }}"

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.DS_Store
22
tmp
33
artifacts
4+
builds
45
*~

README.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,14 @@ The following example uses Docker and assumes you have Docker correctly installe
3636
3) Run the build:
3737
3838
```
39-
mkdir artifacts
40-
docker run --privileged -i \
41-
-v /proc:/proc \
42-
-v ${PWD}/artifacts:/artifacts \
39+
docker run --privileged -i -v /proc:/proc \
4340
-v ${PWD}:/working_dir \
4441
-w /working_dir \
4542
debian:latest \
4643
/bin/bash -s etc/terraform.conf < build.sh
4744
```
4845
49-
4) When done, your image will be in the `artifacts` folder.
46+
4) When done, your image will be in the `builds` folder.
5047
5148
## Further Information
5249

build.sh

+79-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
#!/bin/bash
22

3-
CONFIG_FILE="$1"
3+
set -e
44

5-
source "$CONFIG_FILE"
5+
# check for root permissions
6+
if [[ "$(id -u)" != 0 ]]; then
7+
echo "E: Requires root permissions" > /dev/stderr
8+
exit 1
9+
fi
10+
11+
# get config
12+
if [ -n "$1" ]; then
13+
CONFIG_FILE="$1"
14+
else
15+
CONFIG_FILE="etc/terraform.conf"
16+
fi
17+
BASE_DIR="$PWD"
18+
source "$BASE_DIR"/"$CONFIG_FILE"
619

720
echo -e "
821
#----------------------#
@@ -21,11 +34,69 @@ patch -d /usr/lib/live/build/ < live-build-fix-syslinux.patch
2134
# https://salsa.debian.org/installer-team/debootstrap/blob/master/debian/changelog
2235
ln -sfn /usr/share/debootstrap/scripts/gutsy /usr/share/debootstrap/scripts/focal
2336

24-
echo -e "
25-
#----------------------#
26-
# RUN TERRAFORM SCRIPT #
27-
#----------------------#
37+
build () {
38+
BUILD_ARCH="$1"
39+
40+
mkdir -p "$BASE_DIR/tmp/$BUILD_ARCH"
41+
cd "$BASE_DIR/tmp/$BUILD_ARCH" || exit
42+
43+
# remove old configs and copy over new
44+
rm -rf config auto
45+
cp -r "$BASE_DIR"/etc/* .
46+
# Make sure conffile specified as arg has correct name
47+
cp -f "$BASE_DIR"/"$CONFIG_FILE" terraform.conf
48+
49+
# Symlink chosen package lists to where live-build will find them
50+
ln -s "package-lists.$PACKAGE_LISTS_SUFFIX" "config/package-lists"
51+
# symlink appcenter archive
52+
if [ "$INCLUDE_APPCENTER" = "yes" ]; then
53+
ln -s "appcenter/appcenter.list.binary" "archives/appcenter.list.binary"
54+
ln -s "appcenter/appcenter.key.binary" "archives/appcenter.key.binary"
55+
fi
56+
57+
echo -e "
58+
#------------------#
59+
# LIVE-BUILD CLEAN #
60+
#------------------#
2861
"
62+
lb clean
63+
64+
echo -e "
65+
#-------------------#
66+
# LIVE-BUILD CONFIG #
67+
#-------------------#
68+
"
69+
lb config
70+
71+
echo -e "
72+
#------------------#
73+
# LIVE-BUILD BUILD #
74+
#------------------#
75+
"
76+
lb build
77+
78+
echo -e "
79+
#---------------------------#
80+
# MOVE OUTPUT TO BUILDS DIR #
81+
#---------------------------#
82+
"
83+
84+
YYYYMMDD="$(date +%Y%m%d)"
85+
OUTPUT_DIR="$BASE_DIR/builds/$BUILD_ARCH"
86+
mkdir -p "$OUTPUT_DIR"
87+
FNAME="elementaryos-$VERSION-$CHANNEL.$YYYYMMDD$OUTPUT_SUFFIX"
88+
mv "$BASE_DIR/tmp/$BUILD_ARCH/live-image-$BUILD_ARCH.hybrid.iso" "$OUTPUT_DIR/${FNAME}.iso"
89+
90+
md5sum "$OUTPUT_DIR/${FNAME}.iso" > "$OUTPUT_DIR/${FNAME}.md5.txt"
91+
sha256sum "$OUTPUT_DIR/${FNAME}.iso" > "$OUTPUT_DIR/${FNAME}.sha256.txt"
92+
}
93+
94+
# remove old builds before creating new ones
95+
rm -rf "$BASE_DIR"/builds
2996

30-
./terraform.sh --config-path "$CONFIG_FILE"
31-
cp builds/amd64/* /artifacts/
97+
if [[ "$ARCH" == "all" ]]; then
98+
build amd64
99+
build i386
100+
else
101+
build "$ARCH"
102+
fi

etc/terraform-daily-5.1-azure.conf

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ MIRROR_URL="http://azure.archive.ubuntu.com/ubuntu/"
2525
# use HWE kernel and packages?
2626
HWE="yes"
2727

28+
# use appcenter ppa
29+
INCLUDE_APPCENTER="yes"
30+
2831
# suffix for generated .iso files
2932
OUTPUT_SUFFIX=""
3033

etc/terraform-daily-6.0-azure.conf

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ MIRROR_URL="http://azure.archive.ubuntu.com/ubuntu/"
2525
# use HWE kernel and packages?
2626
HWE=""
2727

28+
# use appcenter ppa
29+
INCLUDE_APPCENTER=""
30+
2831
# suffix for generated .iso files
2932
OUTPUT_SUFFIX="-distinst"
3033

etc/terraform-daily-distinst-azure.conf

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ MIRROR_URL="http://azure.archive.ubuntu.com/ubuntu/"
2525
# use HWE kernel and packages?
2626
HWE="yes"
2727

28+
# use appcenter ppa
29+
INCLUDE_APPCENTER="yes"
30+
2831
# suffix for generated .iso files
2932
OUTPUT_SUFFIX="-distinst"
3033

etc/terraform-stable-azure.conf

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ MIRROR_URL="http://azure.archive.ubuntu.com/ubuntu/"
2525
# use HWE kernel and packages?
2626
HWE="yes"
2727

28+
# use appcenter ppa
29+
INCLUDE_APPCENTER="yes"
30+
2831
# suffix for generated .iso files
2932
OUTPUT_SUFFIX=""
3033

etc/terraform.conf

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ MIRROR_URL="http://archive.ubuntu.com/ubuntu/"
2525
# use HWE kernel and packages?
2626
HWE="yes"
2727

28+
# use appcenter ppa
29+
INCLUDE_APPCENTER="yes"
30+
2831
# suffix for generated .iso files
2932
OUTPUT_SUFFIX=""
3033

terraform.sh

-108
This file was deleted.

upload.sh

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
set -e
4+
35
CONFIG_FILE="$1"
46
KEY="$2"
57
SECRET="$3"
@@ -28,14 +30,17 @@ python3 get-pip.py
2830
pip install boto3
2931

3032
# get the paths & filenames of the files to upload
31-
ISOPATH="$(find /artifacts -name "*.iso")"
32-
ISO="$CHANNEL/$(basename "$ISOPATH")"
33-
ISOTAG="$(basename "$ISOPATH" .iso)"
34-
SHAPATH="$(find /artifacts -name "*.sha256.txt")"
35-
SHASUM="$CHANNEL/$ISOTAG.sha256.txt"
36-
MD5PATH="$(find /artifacts -name "*.md5.txt")"
37-
MD5="$CHANNEL/$ISOTAG.md5.txt"
38-
39-
python3 upload.py "$KEY" "$SECRET" "$ENDPOINT" "$BUCKET" "$ISOPATH" "$ISO"
40-
python3 upload.py "$KEY" "$SECRET" "$ENDPOINT" "$BUCKET" "$SHAPATH" "$SHASUM"
41-
python3 upload.py "$KEY" "$SECRET" "$ENDPOINT" "$BUCKET" "$MD5PATH" "$MD5"
33+
ISOPATHS="$(find builds -name "*.iso")"
34+
while IFS= read -r ISOPATH; do
35+
SHAPATH="${ISOPATH%.*}.sha256.txt"
36+
MD5PATH="${ISOPATH%.*}.md5.txt"
37+
ISO="$CHANNEL/$(basename "$ISOPATH")"
38+
SHASUM="$CHANNEL/$(basename "$SHAPATH")"
39+
MD5="$CHANNEL/$(basename "$MD5PATH")"
40+
echo "uploading $ISO..."
41+
python3 upload.py "$KEY" "$SECRET" "$ENDPOINT" "$BUCKET" "$ISOPATH" "$ISO" || exit 1
42+
echo "uploading $SHASUM..."
43+
python3 upload.py "$KEY" "$SECRET" "$ENDPOINT" "$BUCKET" "$SHAPATH" "$SHASUM" || exit 1
44+
echo "uploading $MD5..."
45+
python3 upload.py "$KEY" "$SECRET" "$ENDPOINT" "$BUCKET" "$MD5PATH" "$MD5" || exit 1
46+
done <<< "$ISOPATHS"

workflows.sh

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
set -e
4+
35
CONFIG_FILE="$1"
46
KEY="$2"
57
SECRET="$3"

0 commit comments

Comments
 (0)