Skip to content

Commit

Permalink
Merge pull request #20 from balena-io/add-build-script
Browse files Browse the repository at this point in the history
Add automation build script
  • Loading branch information
bulldozer-balena[bot] authored May 25, 2020
2 parents 85bed94 + d25289a commit e0a57cd
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 24 deletions.
3 changes: 1 addition & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Dockerfile
.git
Dockerfile
36 changes: 14 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
# Use this dockerfile to build the qemu binary
FROM debian:stretch

FROM debian:jessie

RUN apt-get update \
&& apt-get install -y \
autoconf \
bison \
build-essential \
flex \
libglib2.0-dev \
libtool \
make \
pkg-config \
python \
libpixman-1-dev \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get -q update \
&& apt-get -qqy install \
build-essential \
zlib1g-dev \
libpixman-1-dev \
python \
libglib2.0-dev \
pkg-config \
curl \
jq \
git \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/qemu

COPY . /usr/src/qemu


ARG TARGET_ARCH=arm-linux-user
RUN ./configure --target-list=$TARGET_ARCH --static --extra-cflags="-DCONFIG_RTNETLINK"

RUN make -j $(nproc)
CMD ./build.sh
28 changes: 28 additions & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Use this dockerfile to build the qemu binary

FROM debian:jessie

RUN apt-get update \
&& apt-get install -y \
autoconf \
bison \
build-essential \
flex \
libglib2.0-dev \
libtool \
make \
pkg-config \
python \
libpixman-1-dev \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/qemu

COPY . /usr/src/qemu


ARG TARGET_ARCH=arm-linux-user
RUN ./configure --target-list=$TARGET_ARCH --static --extra-cflags="-DCONFIG_RTNETLINK"

RUN make -j $(nproc)
12 changes: 12 additions & 0 deletions automation/jenkins-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -e
set -o pipefail

docker build -t qemu-builder .

docker run --rm -e ACCOUNT=$ACCOUNT \
-e REPO=$REPO \
-e ACCESS_TOKEN=$ACCESS_TOKEN \
-e QEMU_VERSION=$QEMU_VERSION \
-e RELEASE_BRANCH=$RELEASE_BRANCH \
-e RELEASE_COMMIT=$RELEASE_COMMIT qemu-builder
58 changes: 58 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

set -o errexit

git checkout "$RELEASE_COMMIT"

TARGETS="arm aarch64"

for TARGET in $TARGETS; do
BINARY_NAME="qemu-$TARGET-static"
PACKAGE_NAME="qemu-$QEMU_VERSION-$TARGET"

./configure --target-list="$TARGET-linux-user" --static --extra-cflags="-DCONFIG_RTNETLINK" \
&& make -j $(nproc) \
&& strip "$TARGET-linux-user/qemu-$TARGET" \
&& mkdir -p "$PACKAGE_NAME" \
&& cp "$TARGET-linux-user/qemu-$TARGET" "$PACKAGE_NAME/$BINARY_NAME"

tar -cvzf "$PACKAGE_NAME.tar.gz" "$PACKAGE_NAME"
done

ARM_SHA256=$(sha256sum "qemu-$QEMU_VERSION-arm.tar.gz")
AARCH64_SHA256=$(sha256sum "qemu-$QEMU_VERSION-aarch64.tar.gz")
echo "arm: $ARM_SHA256, aarch64: $AARCH64_SHA256"

if [ -z "$ACCOUNT" ] || [ -z "$REPO" ] || [ -z "$ACCESS_TOKEN" ]; then
echo "Please set value for ACCOUNT, REPO and ACCESS_TOKEN!"
exit 1
fi

# Create a release
rm -f request.json response.json
cat > request.json <<-EOF
{
"tag_name": "v$QEMU_VERSION",
"target_commitish": "$RELEASE_BRANCH",
"name": "v$QEMU_VERSION",
"body": "Release of version v$QEMU_VERSION. \nqemu-$QEMU_VERSION-arm.tar.gz - SHA256: ${ARM_SHA256% *}. \nqemu-$QEMU_VERSION-aarch64.tar.gz - SHA256: ${AARCH64_SHA256% *}",
"draft": false,
"prerelease": false
}
EOF
curl --data "@request.json" --header "Content-Type:application/json" \
"https://api.github.com/repos/$ACCOUNT/$REPO/releases?access_token=$ACCESS_TOKEN" \
-o response.json
# Parse response
RELEASE_ID=$(cat response.json | jq '.id')
echo "RELEASE_ID=$RELEASE_ID"

# Upload data
curl -H "Authorization:token $ACCESS_TOKEN" -H "Content-Type:application/x-gzip" \
--data-binary "@qemu-$QEMU_VERSION-arm.tar.gz" \
"https://uploads.github.com/repos/$ACCOUNT/$REPO/releases/$RELEASE_ID/assets?name=qemu-$QEMU_VERSION-arm.tar.gz"

# Upload data
curl -H "Authorization:token $ACCESS_TOKEN" -H "Content-Type:application/x-gzip" \
--data-binary "@qemu-$QEMU_VERSION-aarch64.tar.gz" \
"https://uploads.github.com/repos/$ACCOUNT/$REPO/releases/$RELEASE_ID/assets?name=qemu-$QEMU_VERSION-aarch64.tar.gz"

0 comments on commit e0a57cd

Please sign in to comment.