Skip to content

Commit b4fcc75

Browse files
authored
Merge pull request #8 from lumastar/rename-scripts
Rename scripts
2 parents 1fd2d76 + e5ce1d9 commit b4fcc75

File tree

6 files changed

+105
-105
lines changed

6 files changed

+105
-105
lines changed

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ stages:
1313
job test:
1414
stage: test
1515
script:
16-
- ./build-docker.sh
16+
- ./build.sh

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ services:
66
- docker
77

88
script:
9-
- ./build-docker.sh
9+
- ./build.sh

Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ RUN apt-get -y update && \
1212
dosfstools \
1313
xxd
1414

15-
WORKDIR /build/
15+
WORKDIR /raspbian-customiser/
1616

17-
COPY build.sh /build/
18-
COPY add-partition.sh /build/
19-
COPY mount.sh /build/
17+
COPY customise.sh /raspbian-customiser/
18+
COPY add-partition.sh /raspbian-customiser/
19+
COPY mount.sh /raspbian-customiser/
2020

21-
ENTRYPOINT /build/build.sh
21+
ENTRYPOINT /raspbian-customiser/customise.sh

build-docker.sh

Lines changed: 0 additions & 54 deletions
This file was deleted.

build.sh

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,54 @@
11
#!/usr/bin/env bash
22

33
set -o errexit
4-
set -o nounset
54
set -o pipefail
65
set -o xtrace
76

8-
ADD_DATA_PART=${ADD_DATA_PART:-false}
9-
10-
# These are the env vars that should be passed in from docker
11-
echo "MOUNT: $MOUNT"
12-
echo "SOURCE_IMAGE: $SOURCE_IMAGE"
13-
echo "SCRIPT: $SCRIPT"
14-
echo "ADD_DATA_PART: $ADD_DATA_PART"
15-
16-
# If ADD_DATA_PART is true then add a data partiton
17-
if [ $ADD_DATA_PART != false ]; then
18-
source ./add-partition.sh $SOURCE_IMAGE
19-
# The add-partition script runs mount
7+
if [ ! -z "$TRAVIS_BRANCH" ]; then
8+
# For tag builds TRAVIS_BRANCH is set to the tag name
9+
BRANCH=$TRAVIS_BRANCH
10+
# For PR builds branch is the target branch
11+
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
12+
# Change the branch name for PR builds so we don't create a tag
13+
BRANCH="${BRANCH}-${TRAVIS_PULL_REQUEST}"
14+
fi
15+
# Only Travis should push images, so we only need to use the tag with Travis
16+
TAG=$TRAVIS_TAG
17+
elif [ ! -z "$CI_COMMIT_REF_NAME" ]; then
18+
# This is also run in GitLab CI, for build and test only.
19+
BRANCH="$CI_COMMIT_REF_NAME"
2020
else
21-
# Or mount is run here directly
22-
source ./mount.sh $SOURCE_IMAGE
21+
exit 1
2322
fi
2423

25-
# The add-partition or mount scripts must set LOOP_DEV and ROOTFS_DIR
26-
echo "LOOP_DEV: $LOOP_DEV"
27-
echo "ROOTFS_DIR: $ROOTFS_DIR"
28-
29-
# Bind mount the directory specified as MOUNT. This is for scripts to run
30-
# inside Raspbian and data to copy in
31-
mkdir ${ROOTFS_DIR}/${MOUNT}
32-
mount --bind $MOUNT ${ROOTFS_DIR}/${MOUNT}
33-
34-
# Apply ld.so.preload fix
35-
sed -i 's/^/#CHROOT /g' /mnt/raspbian/etc/ld.so.preload
36-
37-
# Copy qemu binary
38-
cp /usr/bin/qemu-arm-static ${ROOTFS_DIR}/usr/bin/
39-
40-
# Enable qemu-arm
41-
update-binfmts --enable qemu-arm
42-
43-
# Chroot to the mounted Raspbian environment and run the SCRIPT
44-
chroot ${ROOTFS_DIR} $SCRIPT
45-
46-
# Revert ld.so.preload fix
47-
sed -i 's/^#CHROOT //g' ${ROOTFS_DIR}/etc/ld.so.preload
24+
# Set TAG to false if unset
25+
TAG="${TAG:-false}"
26+
# Delay setting this until all used variables are set
27+
set -o nounset
4828

49-
# Unmount everything
50-
if [ $ADD_DATA_PART != false ]; then
51-
umount ${ROOTFS_DIR}/data
29+
echo "BUILD - Will now build Docker container"
30+
docker build -t lumastar/raspbian-customiser:$BRANCH .
31+
32+
echo "TEST - Will now test built Docker container"
33+
IMAGE_LINK=http://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2018-10-11/2018-10-09-raspbian-stretch-lite.zip
34+
cd test/
35+
wget -nv $IMAGE_LINK
36+
IMAGE_ZIP=$(basename $IMAGE_LINK)
37+
unzip -o $IMAGE_ZIP
38+
rm $IMAGE_ZIP
39+
cd ..
40+
docker run --privileged --rm \
41+
-e MOUNT=/test \
42+
-e SOURCE_IMAGE=/test/${IMAGE_ZIP%.zip}.img \
43+
-e SCRIPT=/test/test.sh \
44+
-e ADD_DATA_PART=true \
45+
--mount type=bind,source="$(pwd)"/test,destination=/test \
46+
lumastar/raspbian-customiser:$BRANCH
47+
48+
if [ "$TAG" != "false" ]; then
49+
# Only push image if TAG is not false
50+
echo "DEPLOY - Will now push Docker image to Quay.io repository as $TAG"
51+
echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin quay.io
52+
docker tag lumastar/raspbian-customiser:$BRANCH quay.io/lumastar/raspbian-customiser:$TAG
53+
docker push quay.io/lumastar/raspbian-customiser:$TAG
5254
fi
53-
umount ${ROOTFS_DIR}/{dev/pts,dev,sys,proc,boot,${MOUNT},}
54-
losetup -d $LOOP_DEV
55-
echo "SUCCESSFULLY UNMOUNTED IMG"

customise.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
set -o xtrace
7+
8+
ADD_DATA_PART=${ADD_DATA_PART:-false}
9+
10+
# These are the env vars that should be passed in from docker
11+
echo "MOUNT: $MOUNT"
12+
echo "SOURCE_IMAGE: $SOURCE_IMAGE"
13+
echo "SCRIPT: $SCRIPT"
14+
echo "ADD_DATA_PART: $ADD_DATA_PART"
15+
16+
# If ADD_DATA_PART is true then add a data partiton
17+
if [ $ADD_DATA_PART != false ]; then
18+
source ./add-partition.sh $SOURCE_IMAGE
19+
# The add-partition script runs mount
20+
else
21+
# Or mount is run here directly
22+
source ./mount.sh $SOURCE_IMAGE
23+
fi
24+
25+
# The add-partition or mount scripts must set LOOP_DEV and ROOTFS_DIR
26+
echo "LOOP_DEV: $LOOP_DEV"
27+
echo "ROOTFS_DIR: $ROOTFS_DIR"
28+
29+
# Bind mount the directory specified as MOUNT. This is for scripts to run
30+
# inside Raspbian and data to copy in
31+
mkdir ${ROOTFS_DIR}/${MOUNT}
32+
mount --bind $MOUNT ${ROOTFS_DIR}/${MOUNT}
33+
34+
# Apply ld.so.preload fix
35+
sed -i 's/^/#CHROOT /g' /mnt/raspbian/etc/ld.so.preload
36+
37+
# Copy qemu binary
38+
cp /usr/bin/qemu-arm-static ${ROOTFS_DIR}/usr/bin/
39+
40+
# Enable qemu-arm
41+
update-binfmts --enable qemu-arm
42+
43+
# Chroot to the mounted Raspbian environment and run the SCRIPT
44+
chroot ${ROOTFS_DIR} $SCRIPT
45+
46+
# Revert ld.so.preload fix
47+
sed -i 's/^#CHROOT //g' ${ROOTFS_DIR}/etc/ld.so.preload
48+
49+
# Unmount everything
50+
if [ $ADD_DATA_PART != false ]; then
51+
umount ${ROOTFS_DIR}/data
52+
fi
53+
umount ${ROOTFS_DIR}/{dev/pts,dev,sys,proc,boot,${MOUNT},}
54+
losetup -d $LOOP_DEV
55+
echo "SUCCESSFULLY UNMOUNTED IMG"

0 commit comments

Comments
 (0)