Skip to content

Commit 2834d5b

Browse files
committed
tooling: Update build scripts for new build process
1 parent 7ee51c8 commit 2834d5b

File tree

14 files changed

+1156
-162
lines changed

14 files changed

+1156
-162
lines changed

.github/actions/publish-packages/Dockerfile

-3
This file was deleted.

.github/actions/publish-packages/README.md

-12
This file was deleted.

.github/workflows/publish-testing.yml

+12-30
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,25 @@ on:
55
- testing
66
jobs:
77
images:
8-
name: Publish images
8+
name: Build and publish images
99
runs-on: ubuntu-latest
10-
strategy:
11-
matrix:
12-
image: [
13-
base,
14-
qt,
15-
python,
16-
rust
17-
]
18-
# Build images one at a time, since we can’t specify fine-grained
19-
# dependencies and all images depend on the 'base' one
20-
max-parallel: 1
2110
steps:
2211
- name: Checkout the Git repository
2312
uses: actions/checkout@v2
24-
- name: Publish images
25-
uses: docker/build-push-action@v1
26-
with:
27-
tags: testing
28-
build_args: BASE=docker.pkg.github.com/${{ github.repository }}/base:testing
29-
username: ${{ github.actor }}
30-
password: ${{ secrets.GITHUB_TOKEN }}
31-
registry: docker.pkg.github.com
32-
repository: ${{ github.repository }}/${{ matrix.image }}
33-
path: image/${{ matrix.image }}
13+
- name: Build and publish images
14+
run: |
15+
echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
16+
./scripts/build-images -p image
3417
packages:
3518
needs: images
36-
name: Publish packages
19+
name: Build and publish packages
3720
runs-on: ubuntu-latest
3821
steps:
3922
- name: Checkout the Git repository
4023
uses: actions/checkout@v2
41-
- name: Publish packages
42-
uses: ./.github/actions/publish-packages
43-
env:
44-
REMOTE_PATH: /srv/toltec/testing
45-
REMOTE: ${{ secrets.REMOTE }}
46-
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
47-
SSH_KNOWN_HOSTS: ${{ secrets.SSH_KNOWN_HOSTS }}
24+
- name: Build packages
25+
run: ./scripts/build-repo package build
26+
- uses: actions/upload-artifact@v2
27+
with:
28+
name: repo
29+
path: build/repo

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
private
22
build
3+
__pycache__

Makefile

+15-25
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,23 @@
1-
PACKAGE?=draft
21
HOST?=10.11.99.1
3-
4-
default: repo
5-
repo: docker_images
6-
bash scripts/build-repo-in-docker
7-
8-
# Use `make <app>` to build any package individually
9-
# Use `make push_<app>` to push any package to .cache/opkg/ on the rM
102
PACKAGES=$(shell ls package/)
11-
PUSH_PACKAGES=$(foreach app, $(PACKAGES), push_$(app))
3+
PUSH_PACKAGES=$(foreach app, $(PACKAGES), push-$(app))
124

13-
$(PACKAGES): %:
14-
PACKAGE=$(@) make package
5+
help:
6+
@echo "Available recipes: ${PACKAGES}"
7+
@echo
8+
@echo "Use 'make repo' to build all the packages and the index file"
9+
@echo "Use 'make <recipe>' to build any package individually"
10+
@echo "Use 'make push-<recipe>' to push any built package to .cache/opkg on the reMarkable"
1511

16-
$(PUSH_PACKAGES): %:
17-
PACKAGE=$(@:push_%=%) make push_package
12+
repo:
13+
./scripts/build-repo package build
1814

19-
package: docker_images
20-
echo "BUILDING ${PACKAGE}"
21-
PACKAGE=${PACKAGE} bash scripts/build-package-in-docker
22-
23-
push_package:
24-
ssh root@${HOST} mkdir -p .cache/opkg/
25-
PACKAGE=${PACKAGE} scp artifacts/package/${PACKAGE}/*.ipk root@${HOST}:.cache/opkg/
15+
$(PACKAGES): %:
16+
./scripts/build-package package/"$(@)" build/packages/"$(@)"
2617

27-
docker_images:
28-
docker build --tag toltec:base . -f image/base/Dockerfile
29-
docker build --tag toltec:rm . -f image/rm_toolchain/Dockerfile --build-arg "BASE=toltec:base"
30-
docker build --tag toltec:build . -f image/build/Dockerfile
3118

32-
.PHONY: docker package
19+
$(PUSH_PACKAGES): %:
20+
ssh root@"${HOST}" mkdir -p .cache/opkg/
21+
scp build/packages/"$(@:push-%=%)"/*.ipk root@"${HOST}":.cache/opkg
3322

23+
.PHONY: help repo $(PACKAGES) $(PUSH_PACKAGES)

scripts/build-images

+13-12
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@ Unchanged images will not be rebuilt.
1010
1111
Options:
1212
13+
-h Show this help message.
1314
-p Publish each built image to the GitHub Container Registry
1415
(you need to be logged in to ghcr.io with the appropriate
15-
permissions for this to work).
16+
permissions for this to work)."
1617

17-
-h Show this help message."
1818

19-
publishflag=
2019
helpflag=
21-
imagesdir=
20+
publishflag=
2221

23-
while getopts ph name; do
22+
while getopts hp name; do
2423
case $name in
25-
p) publishflag=1 ;;
2624
h) helpflag=1 ;;
25+
p) publishflag=1 ;;
2726
*) error "Invalid option. Use the -h flag for more information." ;;
2827
esac
2928
done
@@ -67,12 +66,14 @@ docker-build base
6766
popd
6867

6968
for imagepath in "$imagesdir"/*; do
70-
imagename="$(basename "$imagepath")"
71-
72-
if [[ $imagename != base ]]; then
73-
pushd "$imagepath"
74-
docker-build "$imagename"
75-
popd
69+
if [[ -d $imagepath ]]; then
70+
imagename="$(basename "$imagepath")"
71+
72+
if [[ $imagename != base ]]; then
73+
pushd "$imagepath"
74+
docker-build "$imagename"
75+
popd
76+
fi
7677
fi
7778
done
7879

scripts/build-package

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ if [[ -n $helpflag ]]; then
2929
fi
3030

3131
if [[ $# -eq 0 ]]; then
32-
error "Missing RECIPEDIR and WORKDIR arguments. Use the --help flag for more information."
32+
error "Missing RECIPEDIR and WORKDIR arguments. Use the -h flag for more information."
3333
fi
3434

3535
if [[ $# -eq 1 ]]; then
36-
error "Missing WORKDIR argument. Use the --help flag for more information."
36+
error "Missing WORKDIR argument. Use the -h flag for more information."
3737
fi
3838

3939
if [[ $# -gt 2 ]]; then
@@ -45,7 +45,7 @@ workdir="$2"
4545

4646
# Create working directories
4747
[[ -d $workdir ]] && files="$(ls -qA -- "$workdir")" && [[ -n $files ]] \
48-
&& error "Working directory exists and is not empty"
48+
&& error "Working directory '$workdir' exists and is not empty"
4949
mkdir -p "$workdir"
5050

5151
srcdir="$workdir"/src

scripts/build-repo

+57-25
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,87 @@
11
#!/usr/bin/env bash
22

3+
set -e
34
source "${BASH_SOURCE%/*}"/lib
4-
usage="$0 PACKAGESDIR WORKDIR
55

6-
Build all packages described in PACKAGESDIR.
7-
The WORKDIR must be a non-existent directory in which the build is performed.
6+
usage="$0 [OPTION]... RECIPESDIR WORKDIR
87
9-
Arguments:
8+
Build new or updated packages defined in RECIPESDIR and create a package index.
9+
The WORKDIR must be a non-existent directory in which the builds are performed.
1010
11-
-h, --help Show this help message."
11+
Options:
1212
13-
if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
13+
-h Show this help message.
14+
-f Force building all the packages, even those for which
15+
an already built version exists on the remote."
16+
17+
helpflag=
18+
forceflag=
19+
20+
while getopts hf name; do
21+
case $name in
22+
h) helpflag=1 ;;
23+
f) forceflag=1 ;;
24+
*) error "Invalid option. Use the -h flag for more information." ;;
25+
esac
26+
done
27+
28+
shift $((OPTIND - 1))
29+
30+
if [[ -n $helpflag ]]; then
1431
echo "$usage"
1532
exit
1633
fi
1734

18-
if [[ $# -lt 2 ]]; then
19-
error "Missing arguments. Use the --help flag for more information."
35+
if [[ $# -eq 0 ]]; then
36+
error "Missing RECIPESDIR and WORKDIR arguments. Use the -h flag for more information."
2037
fi
2138

22-
pkgsdir="$1"
23-
workdir="$2"
39+
if [[ $# -eq 1 ]]; then
40+
error "Missing WORKDIR argument. Use the -h flag for more information."
41+
fi
42+
43+
if [[ $# -gt 2 ]]; then
44+
error "Extraneous arguments. Use the -h flag for more information."
45+
fi
2446

25-
[[ -d $workdir ]] && files="$(ls -qA -- "$workdir")" && [[ -n $files ]] \
26-
&& error "Working directory exists and is not empty"
27-
mkdir -p "$workdir"
47+
recipesdir="$1"
48+
workdir="$2"
2849

29-
pkgsworkdir="$workdir"/package
30-
mkdir "$pkgsworkdir"
50+
pkgsworkdir="$workdir"/packages
51+
mkdir -p "$pkgsworkdir"
3152

3253
repodir="$workdir"/repo
33-
mkdir "$repodir"
54+
55+
[[ -d $repodir ]] && files="$(ls -qA -- "$repodir")" && [[ -n $files ]] \
56+
&& error "Repository directory '$repodir' exists and is not empty"
57+
mkdir -p "$repodir"
58+
59+
# URL to the remote repository
60+
branch="$(git branch --show-current)"
61+
remote="https://toltec.delab.re/$branch"
3462

3563
# Define the SOURCE_DATE_EPOCH to the date of latest commit
3664
# See <https://reproducible-builds.org/docs/source-date-epoch/>
3765
SOURCE_DATE_EPOCH="$(git log -1 --pretty=%ct)"
3866
export SOURCE_DATE_EPOCH
3967

40-
# Build each individual package
41-
for pkgpath in "$pkgsdir"/*
42-
do
43-
pkgname="$(basename "$pkgpath")"
44-
pkgworkdir="$pkgsworkdir"/"$pkgname"
45-
status "Building $pkgname in $pkgworkdir"
68+
# Build each package or get it from the remote server
69+
for recipedir in "$recipesdir"/*; do
70+
load-recipe "$recipedir"
71+
arname="$(archive-name "$recipedir")"
4672

47-
"${BASH_SOURCE%/*}"/build-package "$pkgpath" "$pkgworkdir"
48-
mv "$pkgworkdir"/*.ipk "$repodir"
73+
if [[ -n $forceflag ]] || ! rcurl "$remote"/"$arname" -o "$repodir"/"$arname"; then
74+
pkgworkdir="$pkgsworkdir"/"$pkgname"
75+
status "Building $pkgname in $pkgworkdir"
76+
"${BASH_SOURCE%/*}"/build-package "$recipedir" "$pkgworkdir"
77+
mv "$pkgworkdir"/*.ipk "$repodir"
78+
else
79+
status "Reusing already built $pkgname from remote"
80+
fi
4981
done
5082

5183
# Build packages index
52-
opkg-make-index --checksum sha256 -p "$repodir"/Packages "$repodir"
84+
"${BASH_SOURCE%/*}"/opkg/opkg-make-index --checksum sha256 -p "$repodir"/Packages "$repodir"
5385

5486
# Set atime and mtime to fixed timestamp for all files
5587
find "$repodir" -exec touch --no-dereference --date="@${SOURCE_DATE_EPOCH}" {} +

scripts/build-repo-in-docker

-8
This file was deleted.

scripts/lib

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ rtar() {
2929
"$@"
3030
}
3131

32+
# Curl command with flags suitable for scripting
33+
rcurl() {
34+
curl --tlsv1.2 --proto '=https' "$@" --fail --silent
35+
}
36+
3237
# Load information from a package recipe
3338
#
3439
# Arguments:

0 commit comments

Comments
 (0)