Skip to content

Commit

Permalink
Improve build&package
Browse files Browse the repository at this point in the history
  • Loading branch information
dswd committed Feb 22, 2021
1 parent 5176c32 commit f11c0ef
Show file tree
Hide file tree
Showing 20 changed files with 311 additions and 102 deletions.
4 changes: 1 addition & 3 deletions .github/actions/build-deb/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ RUN apt-get update \
libc6-dev-i386 \
gcc-5-multilib \
asciidoctor \
&& rm -rf /var/cache/dpkg

RUN ln -s asm-generic/ /usr/include/asm
&& apt-get clean && rm -rf /var/lib/apt/lists/*

ADD entrypoint.sh /entrypoint.sh

Expand Down
6 changes: 0 additions & 6 deletions .github/actions/build-deb/action.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
name: 'build-deb'
description: 'Create deb packages'
inputs:
rust:
description: Rust version
default: 'stable'
runs:
using: 'docker'
image: 'Dockerfile'
env:
RUST: ${{ inputs.rust }}
33 changes: 18 additions & 15 deletions .github/actions/build-deb/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

set -e

curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain ${RUST}
TOOLCHAIN=$(grep -e '^toolchain =' Cargo.toml | sed -e 's/toolchain = "\(.*\)"/\1/')

VERSION=$(grep -e '^version =' Cargo.toml | sed -e 's/version = "\(.*\)"/\1/')
DEB_VERSION=$(echo "$VERSION" | sed -e 's/-/~/g')

ln -s asm-generic/ /usr/include/asm

curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain ${TOOLCHAIN}
source $HOME/.cargo/env

rustup target add i686-unknown-linux-gnu
Expand All @@ -11,22 +18,18 @@ rustup target add aarch64-unknown-linux-gnu

cargo install cargo-deb

VERSION=$(grep -e '^version =' Cargo.toml | sed -e 's/version = "\(.*\)"/\1/')
DEB_VERSION=$(echo "$VERSION" | sed -e 's/-/~/g')

mkdir dist

build_deb() {
ARCH=$1
TARGET=$2
cargo deb --target ${TARGET}
cp target/${TARGET}/debian/vpncloud_${DEB_VERSION}_${ARCH}.deb dist/vpncloud_${DEB_VERSION}_${ARCH}.deb
}

cargo deb
cp target/debian/vpncloud_${DEB_VERSION}_amd64.deb dist/vpncloud_${DEB_VERSION}_amd64.deb

# i386 deb
cargo deb --target i686-unknown-linux-gnu
cp target/i686-unknown-linux-gnu/debian/vpncloud_${DEB_VERSION}_i386.deb dist/vpncloud_${DEB_VERSION}_i386.deb

# arm7hf deb
cargo deb --target armv7-unknown-linux-gnueabihf
cp target/armv7-unknown-linux-gnueabihf/debian/vpncloud_${DEB_VERSION}_armhf.deb dist/vpncloud_${DEB_VERSION}_armhf.deb

# aarch64 deb
cargo deb --target aarch64-unknown-linux-gnu
cp target/aarch64-unknown-linux-gnu/debian/vpncloud_${DEB_VERSION}_arm64.deb dist/vpncloud_${DEB_VERSION}_arm64.deb
build_deb i386 i686-unknown-linux-gnu
build_deb armhf armv7-unknown-linux-gnueabihf
build_deb arm64 aarch64-unknown-linux-gnu
3 changes: 3 additions & 0 deletions .github/actions/build-rpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ FROM centos:7

RUN yum groupinstall -y 'Development Tools'
RUN yum install -y ruby && gem install asciidoctor -v 2.0.10
RUN yum install -y libstdc++-*.i686 \
&& yum install -y glibc-*.i686 \
&& yum install -y libgcc.i686

ADD entrypoint.sh /entrypoint.sh

Expand Down
6 changes: 0 additions & 6 deletions .github/actions/build-rpm/action.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
name: 'build-deb'
description: 'Create deb packages'
inputs:
rust:
description: Rust version
default: 'stable'
runs:
using: 'docker'
image: 'Dockerfile'
env:
RUST: ${{ inputs.rust }}
31 changes: 24 additions & 7 deletions .github/actions/build-rpm/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@

set -e

curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain ${RUST}
source $HOME/.cargo/env

rustup target add i686-unknown-linux-gnu
rustup target add armv7-unknown-linux-gnueabihf

cargo install cargo-rpm
TOOLCHAIN=$(grep -e '^toolchain =' Cargo.toml | sed -e 's/toolchain = "\(.*\)"/\1/')

VERSION=$(grep -e '^version =' Cargo.toml | sed -e 's/version = "\(.*\)"/\1/')
if echo "$VERSION" | fgrep -q "-"; then
Expand All @@ -17,8 +11,31 @@ else
RPM_VERSION="$VERSION-1"
fi

curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain ${TOOLCHAIN}
source $HOME/.cargo/env

rustup target add i686-unknown-linux-gnu
rustup target add armv7-unknown-linux-gnueabihf

cargo install cargo-rpm

mkdir dist

cargo build --release
cargo rpm build
cp target/release/rpmbuild/RPMS/x86_64/vpncloud-${RPM_VERSION}.x86_64.rpm dist/vpncloud_${RPM_VERSION}.x86_64.rpm


build_rpm() {
ARCH=$1
TARGET=$2
if ! [ -f dist/vpncloud_${RPM_VERSION}.${ARCH}.rpm ]; then
mkdir -p target
[ -L target/assets ] || ln -s ../assets target/assets
[ -L target/target ] || ln -s ../target target/target
cargo rpm build --target ${TARGET}
cp target/${TARGET}/release/rpmbuild/RPMS/${ARCH}/vpncloud-${RPM_VERSION}.${ARCH}.rpm dist/vpncloud_${RPM_VERSION}.${ARCH}.rpm
fi
}

build_rpm i686 i686-unknown-linux-gnu
19 changes: 19 additions & 0 deletions .github/actions/build-static/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM ubuntu:16.04

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
curl \
gcc-aarch64-linux-gnu \
gcc-arm-linux-gnueabihf \
libc6-dev-arm64-cross \
libc6-dev-armhf-cross \
libc6-dev-i386 \
gcc-5-multilib \
asciidoctor \
musl musl-dev musl-tools \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

ADD entrypoint.sh /entrypoint.sh

ENTRYPOINT /entrypoint.sh
5 changes: 5 additions & 0 deletions .github/actions/build-static/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: 'build-static'
description: 'Create static binaries'
runs:
using: 'docker'
image: 'Dockerfile'
37 changes: 37 additions & 0 deletions .github/actions/build-static/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

set -e

TOOLCHAIN=$(grep -e '^toolchain =' Cargo.toml | sed -e 's/toolchain = "\(.*\)"/\1/')
UPX_VERSION=$(grep -e '^upx_version =' Cargo.toml | sed -e 's/upx_version = "\(.*\)"/\1/')

VERSION=$(grep -e '^version =' Cargo.toml | sed -e 's/version = "\(.*\)"/\1/')
DEB_VERSION=$(echo "$VERSION" | sed -e 's/-/~/g')

ln -s asm-generic/ /usr/include/asm
ln -s /usr/bin/aarch64-linux-gnu-gcc /usr/bin/aarch64-linux-musl-gcc
ln -s /usr/bin/arm-linux-gnueabihf-gcc /usr/bin/arm-linux-musleabihf-gcc

curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain ${TOOLCHAIN}
source $HOME/.cargo/env

rustup target add x86_64-unknown-linux-musl
rustup target add i686-unknown-linux-musl
rustup target add armv7-unknown-linux-musleabihf
rustup target add aarch64-unknown-linux-musl

curl https://github.com/upx/upx/releases/download/v${UPX_VERSION}/upx-${UPX_VERSION}-amd64_linux.tar.xz -Lf | tar -xJ --strip-components=1 -C /opt/rust/cargo/bin

mkdir dist

build_static() {
ARCH=$1
TARGET=$2
cargo build --release --features installer --target ${TARGET} && upx --lzma target/${TARGET}/release/vpncloud
cp target/${TARGET}/release/vpncloud ../dist/vpncloud_${VERSION}_static_${ARCH}
}

build_static amd64 x86_64-unknown-linux-musl
#build_static i386 i686-unknown-linux-musl
build_static armhf armv7-unknown-linux-musleabihf
build_static arm64 aarch64-unknown-linux-musl
22 changes: 18 additions & 4 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ jobs:
- uses: actions/checkout@v2
- name: Run builder
uses: ./.github/actions/build-deb
with:
rust: '1.50.0'
- name: Archive artifacts
uses: actions/upload-artifact@v1
with:
Expand All @@ -30,8 +28,6 @@ jobs:
- uses: actions/checkout@v2
- name: Run builder
uses: ./.github/actions/build-rpm
with:
rust: '1.50.0'
- name: Archive artifacts
uses: actions/upload-artifact@v1
with:
Expand All @@ -43,3 +39,21 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: 'dist/*.rpm'
static:
name: "Build static binaries"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run builder
uses: ./.github/actions/build-static
- name: Archive artifacts
uses: actions/upload-artifact@v1
with:
name: packages
path: dist
- name: Upload artifacts
uses: skx/github-action-publish-binaries@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: 'dist/*'
1 change: 1 addition & 0 deletions .rpm/vpncloud.spec
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
rm -rf %{buildroot}
mkdir -p %{buildroot}
mkdir -p %{buildroot}/etc/vpncloud
chmod 700 %{buildroot}/etc/vpncloud
mkdir -p %{buildroot}/lib/systemd/system
mkdir -p %{buildroot}/usr/share/man/man1
cp %{buildroot}/../../../../../assets/example.net.disabled %{buildroot}/etc/vpncloud/example.net.disabled
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ This project follows [semantic versioning](http://semver.org).
- [added] Added interactive configuration wizard
- [added] Support for (un-)installation
- [added] Building static binaries
- [added] Building i686 rpm
- [changed] Restructured example config
- [changed] Changed Rust version to 1.50.0
- [changed] Updated dependencies
- [changed] Change permissions of /etc/vpncloud

### v2.1.0 (2021-02-06)

Expand Down
Loading

0 comments on commit f11c0ef

Please sign in to comment.