From e2d363506a76362d7fd8a3bd9aa6e9af6012091d Mon Sep 17 00:00:00 2001 From: Jamil Bou Kheir Date: Thu, 29 Jul 2021 16:06:52 -0700 Subject: [PATCH] use installation script for install --- .ci/build_packages.sh | 85 ++++--------------------------- .github/workflows/ci.yml | 24 +++++++-- Vagrantfile | 21 +++++--- pkg/Dockerfile.release | 4 ++ scripts/install.sh | 40 +++++++++++++++ scripts/provision/centos_7.sh | 11 ++-- scripts/provision/centos_8.sh | 12 +++-- scripts/provision/debian_10.sh | 14 +++-- scripts/provision/fedora_33.sh | 12 +++-- scripts/provision/fedora_34.sh | 10 ++-- scripts/provision/ubuntu_18.04.sh | 10 ++-- scripts/provision/ubuntu_20.04.sh | 12 +++-- 12 files changed, 140 insertions(+), 115 deletions(-) create mode 100755 scripts/install.sh diff --git a/.ci/build_packages.sh b/.ci/build_packages.sh index 22ed29a27..7ffbedd8a 100755 --- a/.ci/build_packages.sh +++ b/.ci/build_packages.sh @@ -1,86 +1,19 @@ #!/usr/bin/env bash set -xe +version=0.2.0-1 base_image="ghcr.io/firezone/${MATRIX_IMAGE}" -tag="ghcr.io/firezone/release-${MATRIX_IMAGE/:/_}" +pkg_file="firezone-${version}-${MATRIX_IMAGE/:/_}.amd64.tar.gz" +image="firezone-${version}-${MATRIX_IMAGE/:/_}:${GITHUB_SHA}" -case $MATRIX_IMAGE in - centos*) - format="rpm" - ;; - fedora*) - format="rpm" - ;; - debian*) - format="deb" - ;; - ubuntu*) - format="deb" - ;; -esac - -# Build intermediate release image -docker buildx build \ - --no-cache \ - --pull \ - --push \ +docker build \ + -t $image \ -f pkg/Dockerfile.release \ - -t $tag \ --platform linux/amd64 \ + --build-arg PKG_FILE=$pkg_file \ --build-arg BASE_IMAGE=$base_image \ - --progress plain \ . - - -case $format in - deb) - version=0.2.0-1 - pkg_dir="${MATRIX_IMAGE/:/_}.amd64" - pkg_file="${pkg_dir}.deb" - final_pkg_file="firezone-${version}-${pkg_file}" - image="ghcr.io/firezone/package-${MATRIX_IMAGE/:/_}" - - docker buildx build \ - --push \ - --pull \ - --no-cache \ - -t $image \ - -f pkg/Dockerfile.deb \ - --platform linux/amd64 \ - --build-arg PKG_DIR=$pkg_dir \ - --build-arg BASE_IMAGE=$tag \ - --progress plain \ - . - - cid=$(docker create $image) - mkdir -p _build - docker cp $cid:/root/$pkg_file ./_build/$final_pkg_file - ;; - - rpm) - version=0.2.0-1 - pkg_dir="firezone-${version}.x86_64" - pkg_file="${pkg_dir}.rpm" - os_dir="${MATRIX_IMAGE/:/_}.x86_64" - final_pkg_file="firezone-${version}-${MATRIX_IMAGE/:/_}.x86_64.rpm" - image="ghcr.io/firezone/package-${MATRIX_IMAGE/:/_}" - - docker buildx build \ - --push \ - --pull \ - --no-cache \ - -t $image \ - -f pkg/Dockerfile.rpm \ - --platform linux/amd64 \ - --build-arg PKG_DIR=$pkg_dir \ - --build-arg OS_DIR=$os_dir \ - --build-arg BASE_IMAGE=$tag \ - --progress plain \ - . - - cid=$(docker create $image) - mkdir -p _build - docker cp $cid:/root/rpmbuild/RPMS/x86_64/$pkg_file ./_build/$final_pkg_file - ;; -esac +cid=$(docker create $image) +mkdir -p _build +docker cp $cid:/root/$pkg_file ./_build/$pkg_file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fdd330bb7..7aedc818a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,6 +64,14 @@ jobs: - name: Run Tests and Upload Coverage Report run: mix coveralls.github --umbrella + + + + + + + + build: needs: unit-integration-test runs-on: ubuntu-20.04 @@ -98,8 +106,12 @@ jobs: with: name: firezone path: | - _build/firezone*.rpm - _build/firezone*.deb + _build/firezone*.tar.gz + + + + + functional-test: needs: build @@ -132,6 +144,11 @@ jobs: - run: vagrant up ${{ matrix.os }} - run: .ci/functional_test.sh + + + + + publish: needs: functional-test runs-on: ubuntu-20.04 @@ -165,8 +182,7 @@ jobs: uses: softprops/action-gh-release@v1 with: files: | - _build/firezone*.deb - _build/firezone*.rpm + _build/firezone*.tar.gz # - name: Upload Release Asset # id: upload-release-asset # uses: actions/upload-release-asset@v1 diff --git a/Vagrantfile b/Vagrantfile index f628b3bba..857fa4248 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -7,70 +7,77 @@ Vagrant.configure('2') do |config| config.vm.define "centos_7" do |centos7| centos7.vm.box = "generic/centos7" centos7.vm.network "forwarded_port", guest: 8800, host: 8800 - source_file = Dir["_build/firezone*centos_7*.rpm"].first + source_file = Dir["_build/firezone*centos_7*.tar.gz"].first if source_file centos7.vm.provision "file", source: source_file, destination: "/tmp/" end + centos7.vm.provision "file", source: "scripts/install.sh", destination: "/tmp/" centos7.vm.provision "shell", path: "scripts/provision/centos_7.sh" end config.vm.define "centos_8" do |centos8| centos8.vm.box = "generic/centos8" centos8.vm.network "forwarded_port", guest: 8800, host: 8801 - source_file = Dir["_build/firezone*centos_8*.rpm"].first + source_file = Dir["_build/firezone*centos_8*.tar.gz"].first if source_file centos8.vm.provision "file", source: source_file, destination: "/tmp/" end + centos8.vm.provision "file", source: "scripts/install.sh", destination: "/tmp/" centos8.vm.provision "shell", path: "scripts/provision/centos_8.sh" end config.vm.define "debian_10" do |debian10| debian10.vm.box = "generic/debian10" debian10.vm.network "forwarded_port", guest: 8800, host: 8802 - source_file = Dir["_build/firezone*debian_10*.deb"].first + source_file = Dir["_build/firezone*debian_10*.tar.gz"].first if source_file debian10.vm.provision "file", source: source_file, destination: "/tmp/" end + debian10.vm.provision "file", source: "scripts/install.sh", destination: "/tmp/" debian10.vm.provision "shell", path: "scripts/provision/debian_10.sh" end config.vm.define "fedora_33" do |fedora33| fedora33.vm.box = "generic/fedora33" fedora33.vm.network "forwarded_port", guest: 8800, host: 8803 - source_file = Dir["_build/firezone*fedora_33*.rpm"].first + source_file = Dir["_build/firezone*fedora_33*.tar.gz"].first if source_file fedora33.vm.provision "file", source: source_file, destination: "/tmp/" end + fedora33.vm.provision "file", source: "scripts/install.sh", destination: "/tmp/" fedora33.vm.provision "shell", path: "scripts/provision/fedora_33.sh" end config.vm.define "fedora_34" do |fedora34| fedora34.vm.box = "generic/fedora34" fedora34.vm.network "forwarded_port", guest: 8800, host: 8804 - source_file = Dir["_build/firezone*fedora_34*.rpm"].first + source_file = Dir["_build/firezone*fedora_34*.tar.gz"].first if source_file fedora34.vm.provision "file", source: source_file, destination: "/tmp/" end + fedora34.vm.provision "file", source: "scripts/install.sh", destination: "/tmp/" fedora34.vm.provision "shell", path: "scripts/provision/fedora_34.sh" end config.vm.define "ubuntu_18.04" do |ubuntu1804| ubuntu1804.vm.box = "generic/ubuntu1804" ubuntu1804.vm.network "forwarded_port", guest: 8800, host: 8805 - source_file = Dir["_build/firezone*ubuntu_18.04*.deb"].first + source_file = Dir["_build/firezone*ubuntu_18.04*.tar.gz"].first if source_file ubuntu1804.vm.provision "file", source: source_file, destination: "/tmp/" end + ubuntu1804.vm.provision "file", source: "scripts/install.sh", destination: "/tmp/" ubuntu1804.vm.provision "shell", path: "scripts/provision/ubuntu_18.04.sh" end config.vm.define "ubuntu_20.04" do |ubuntu2004| ubuntu2004.vm.box = "generic/ubuntu2004" ubuntu2004.vm.network "forwarded_port", guest: 8800, host: 8806 - source_file = Dir["_build/firezone*ubuntu_20.04*.deb"].first + source_file = Dir["_build/firezone*ubuntu_20.04*.tar.gz"].first if source_file ubuntu2004.vm.provision "file", source: source_file, destination: "/tmp/" end + ubuntu2004.vm.provision "file", source: "scripts/install.sh", destination: "/tmp/" ubuntu2004.vm.provision "shell", path: "scripts/provision/ubuntu_20.04.sh" end end diff --git a/pkg/Dockerfile.release b/pkg/Dockerfile.release index 586d17f39..f371635c3 100644 --- a/pkg/Dockerfile.release +++ b/pkg/Dockerfile.release @@ -1,6 +1,8 @@ ARG BASE_IMAGE FROM ${BASE_IMAGE} +ARG PKG_FILE + ENV MIX_ENV prod # Dockerfile-friendly build release @@ -25,3 +27,5 @@ COPY rel rel COPY config config COPY apps apps RUN mix release + +RUN tar -zcf $PKG_FILE -C _build/prod/rel/ firezone diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 000000000..5a8b29139 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,40 @@ +#!/bin/bash +set -e + +os_not_found () { + echo "Operating System not detected. Build from source?" + exit 1 +} + +download_release () { + regex="Operating System: (\w+) ([\d\.]+)" + os=`hostnamectl` + if [[ $os =~ $regex ]]; then + distro="${BASH_REMATCH[1]}" + version="${BASH_REMATCH[2]}" + if [[ -z $distro ]] && [[ -z $version ]]; then + os_not_found + else + echo "Fetching latest release..." + file="firezone-latest-${distro}_${version}.amd64.tar.gz" + curl -L -O "https://github.com/firezone/firezone/releases/${file}" + fi + else + os_not_found + fi +} + +echo "Installing FireZone..." +echo + +if [ -n "$1" ]; then + echo "Package tarball supplied. Skipping download..." + file=$1 +else + download_release +fi + +echo "Extracting package to /opt/firezone..." +tar -zxf $file -C /opt/ + +echo "FireZone installed!" diff --git a/scripts/provision/centos_7.sh b/scripts/provision/centos_7.sh index 0496bffd1..495b50c78 100755 --- a/scripts/provision/centos_7.sh +++ b/scripts/provision/centos_7.sh @@ -23,7 +23,10 @@ yum install -y epel-release elrepo-release yum install -y yum-plugin-elrepo yum install -y kmod-wireguard wireguard-tools -rpm -ivh /tmp/firezone*.rpm -systemctl start firezone.service -systemctl status firezone.service -journalctl -xeu firezone + +file=(/tmp/firezone*.tar.gz) +/tmp/install.sh /tmp/$file + +# systemctl start firezone.service +# systemctl status firezone.service +# journalctl -xeu firezone diff --git a/scripts/provision/centos_8.sh b/scripts/provision/centos_8.sh index 99c9a2a0f..3566e9803 100755 --- a/scripts/provision/centos_8.sh +++ b/scripts/provision/centos_8.sh @@ -22,7 +22,11 @@ systemctl restart postgresql yum install -y epel-release elrepo-release yum install -y kmod-wireguard wireguard-tools -rpm -ivh /tmp/firezone*.rpm -systemctl start firezone.service -systemctl status firezone.service -journalctl -xeu firezone + +file=(/tmp/firezone*.tar.gz) +/tmp/install.sh /tmp/$file + + +# systemctl start firezone.service +# systemctl status firezone.service +# journalctl -xeu firezone diff --git a/scripts/provision/debian_10.sh b/scripts/provision/debian_10.sh index 27f391f4e..112660a36 100755 --- a/scripts/provision/debian_10.sh +++ b/scripts/provision/debian_10.sh @@ -22,7 +22,13 @@ apt-get install -y -q \ wireguard \ wireguard-tools -dpkg --debug=2003 -i /tmp/firezone*.deb -systemctl start firezone || true -systemctl status firezone.service -journalctl -xeu firezone +file=(/tmp/firezone*.tar.gz) +/tmp/install.sh /tmp/$file + + + + + +# systemctl start firezone || true +# systemctl status firezone.service +# journalctl -xeu firezone diff --git a/scripts/provision/fedora_33.sh b/scripts/provision/fedora_33.sh index 9622d5b3d..c4fbd4272 100755 --- a/scripts/provision/fedora_33.sh +++ b/scripts/provision/fedora_33.sh @@ -19,7 +19,11 @@ EOT systemctl enable postgresql systemctl restart postgresql -rpm -ivh /tmp/firezone*.rpm -systemctl start firezone.service -systemctl status firezone.service -journalctl -xeu firezone +file=(/tmp/firezone*.tar.gz) +/tmp/install.sh /tmp/$file + + + +# systemctl start firezone.service +# systemctl status firezone.service +# journalctl -xeu firezone diff --git a/scripts/provision/fedora_34.sh b/scripts/provision/fedora_34.sh index 9622d5b3d..04fcd8932 100755 --- a/scripts/provision/fedora_34.sh +++ b/scripts/provision/fedora_34.sh @@ -19,7 +19,9 @@ EOT systemctl enable postgresql systemctl restart postgresql -rpm -ivh /tmp/firezone*.rpm -systemctl start firezone.service -systemctl status firezone.service -journalctl -xeu firezone +file=(/tmp/firezone*.tar.gz) +/tmp/install.sh /tmp/$file + +# systemctl start firezone.service +# systemctl status firezone.service +# journalctl -xeu firezone diff --git a/scripts/provision/ubuntu_18.04.sh b/scripts/provision/ubuntu_18.04.sh index e2998def6..06521332e 100755 --- a/scripts/provision/ubuntu_18.04.sh +++ b/scripts/provision/ubuntu_18.04.sh @@ -14,7 +14,9 @@ apt-get install -y -q \ systemctl enable postgresql systemctl start postgresql -dpkg -i /tmp/firezone*.deb -systemctl start firezone -systemctl status firezone.service -journalctl -xeu firezone +file=(/tmp/firezone*.tar.gz) +/tmp/install.sh /tmp/$file + +# systemctl start firezone +# systemctl status firezone.service +# journalctl -xeu firezone diff --git a/scripts/provision/ubuntu_20.04.sh b/scripts/provision/ubuntu_20.04.sh index e2998def6..697a56d2f 100755 --- a/scripts/provision/ubuntu_20.04.sh +++ b/scripts/provision/ubuntu_20.04.sh @@ -14,7 +14,11 @@ apt-get install -y -q \ systemctl enable postgresql systemctl start postgresql -dpkg -i /tmp/firezone*.deb -systemctl start firezone -systemctl status firezone.service -journalctl -xeu firezone +file=(/tmp/firezone*.tar.gz) +/tmp/install.sh /tmp/$file + + + +# systemctl start firezone +# systemctl status firezone.service +# journalctl -xeu firezone