diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ddc9984a..57d40fc0a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ defaults: jobs: unit-integration-test: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 env: MIX_ENV: test POSTGRES_HOST: localhost @@ -28,35 +28,41 @@ jobs: steps: - uses: actions/checkout@v2 - name: Install Runtimes - uses: actions/setup-elixir@v1 - with: - elixir-version: "1.11.2" - otp-version: "23.1.2" + run: | + wget -O erlang.deb https://packages.erlang-solutions.com/erlang/debian/pool/esl-erlang_23.1-1~ubuntu~focal_amd64.deb + wget -O elixir.deb https://packages.erlang-solutions.com/erlang/debian/pool/elixir_1.11.2-1~ubuntu~focal_all.deb + sudo dpkg -i erlang.deb + sudo dpkg -i elixir.deb - name: Install Dependencies run: mix deps.get --only test - name: Setup Database run: | mix ecto.create mix ecto.migrate - - name: Run Tests and Upload Coverage Report run: mix coveralls.github --umbrella build: needs: unit-integration-test - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - name: Build packages + - name: Install runtimes run: | - docker build -t fireguard:latest -f pkg/Dockerfile . + curl -sL https://deb.nodesource.com/setup_10.x | bash - + sudo apt install nodejs + wget -O erlang.deb https://packages.erlang-solutions.com/erlang/debian/pool/esl-erlang_23.1-1~ubuntu~focal_amd64.deb + wget -O elixir.deb https://packages.erlang-solutions.com/erlang/debian/pool/elixir_1.11.2-1~ubuntu~focal_all.deb + sudo dpkg -i erlang.deb + sudo dpkg -i elixir.deb + - name: Build release + run: | + scripts/build_prod_release.sh + scripts/build_fireguard_deb.sh - name: Rename Built Artifacts run: | - version="${{ steps.version.outputs.version }}" - cid=$(docker create fireguard:latest) filename="fireguard_${{ github.sha }}-1_amd64.deb" - echo "Extracting built debian package from container ${cid} to filename ${filename}" - docker cp ${cid}:/build/pkg/debian.deb ./${filename} + cp fireguard_amd64.deb ./${filename} - uses: actions/upload-artifact@v2 with: name: fireguard-deb @@ -108,7 +114,7 @@ jobs: publish: needs: build - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') steps: - name: Create Release diff --git a/.gitignore b/.gitignore index 7e0421c05..703de6fac 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,6 @@ npm-debug.log # Development environment configuration .env + +# Built debian packages +*.deb diff --git a/ansible/playbook.yml b/ansible/playbook.yml index c14e01072..ea44ebac0 100644 --- a/ansible/playbook.yml +++ b/ansible/playbook.yml @@ -15,10 +15,35 @@ - curl - gnupg - unzip + - dpkg-dev - wireguard - postgresql - iptables - net-tools + - automake + - autoconf + - libssl-dev + - libncurses5-dev + - zlib1g-dev + - locales + - build-essential + - ca-certificates + + - name: setup nodejs repository + shell: curl -sL https://deb.nodesource.com/setup_10.x | bash - + - name: install nodejs + apt: + install_recommends: no + autoclean: yes + autoremove: yes + pkg: + - nodejs + - name: install erlang + apt: + deb: https://packages.erlang-solutions.com/erlang/debian/pool/esl-erlang_23.1-1~ubuntu~focal_amd64.deb + - name: install elixir + apt: + deb: https://packages.erlang-solutions.com/erlang/debian/pool/elixir_1.11.2-1~ubuntu~focal_all.deb - name: Configure System hosts: all become: yes @@ -33,11 +58,19 @@ line: 'net.ipv6.conf.all.forwarding = 1' - name: apply sysctl shell: sysctl -p -- name: Install FireGuard +- name: Build FireGuard hosts: all - become: yes tasks: - - name: Install FireGuard deb + - name: Compile Release + become: no + environment: + MIX_ENV: prod shell: | - wget https://github.com/CloudFire-LLC/fireguard/releases/download/0.1.7/fireguard_amd64.deb + cd /vagrant + scripts/build_prod_release.sh + scripts/build_fireguard_deb.sh + - name: Install FireGuard deb + become: yes + shell: | + cd /vagrant dpkg -i fireguard_amd64.deb diff --git a/pkg/Dockerfile b/pkg/Dockerfile index 1abbff339..2b6f1140f 100644 --- a/pkg/Dockerfile +++ b/pkg/Dockerfile @@ -1,4 +1,9 @@ -# This Dockerfile builds release packages +# This Dockerfile builds release packages. +# **NOTE**: This is not recommended, as it's possible the deployment +# production environment will diff from the image environment here, +# even if the OS and kernel versions match. +# As such, this script has been deprecated in favor of building the release +# in the production environment. FROM hexpm/elixir:1.11.2-erlang-23.1.2-ubuntu-focal-20201008 AS build # Setup to run build script diff --git a/pkg/debian/DEBIAN/control b/pkg/debian/DEBIAN/control index e547d2d70..b9b1bcc0e 100644 --- a/pkg/debian/DEBIAN/control +++ b/pkg/debian/DEBIAN/control @@ -2,7 +2,7 @@ Package: fireguard Version: 0.1.7-1 Architecture: amd64 Maintainer: CloudFire, LLC -Depends: net-tools (>= 1.60+git20180626.aebd88e-1ubuntu1), systemd (>= 245.4-4ubuntu3.2), openssl (>= 1.1.1f-1ubuntu2), wireguard (>= 1.0.20200319-1ubuntu1), postgresql (>= 12.4-0ubuntu0.20.04.1), iptables (>= 1.8.4-3ubuntu2) +Depends: net-tools (>= 1.60+git20180626.aebd88e-1ubuntu1), systemd (>= 245.4-4ubuntu3.2), openssl (>= 1.1.1f-1ubuntu2), wireguard (>= 1.0.20200319-1ubuntu1), postgresql (>= 12+214ubuntu0.1), iptables (>= 1.8.4-3ubuntu2) Section: net Priority: optional Homepage: https://cloudfire.network diff --git a/scripts/build_fireguard_deb.sh b/scripts/build_fireguard_deb.sh new file mode 100755 index 000000000..7424419d7 --- /dev/null +++ b/scripts/build_fireguard_deb.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +od=$(pwd) +mkdir -p pkg/debian/opt +mv _build/prod/rel/fireguard pkg/debian/opt/fireguard +cd pkg +dpkg-deb --build debian +mv debian.deb fireguard_amd64.deb diff --git a/scripts/build_prod_release.sh b/scripts/build_prod_release.sh index 82657ae13..413131b4e 100755 --- a/scripts/build_prod_release.sh +++ b/scripts/build_prod_release.sh @@ -2,10 +2,12 @@ od=$(pwd) export MIX_ENV=prod - -cd apps/fg_http -npm run deploy --prefix assets -mix phx.digest - +mix local.hex --force && mix local.rebar --force +mix do deps.get, deps.compile +cd apps/fg_http/assets && npm ci --progress=false --no-audit --loglevel=error cd $od -mix release +npm run --prefix apps/fg_http/assets deploy +cd apps/fg_http +mix phx.digest +cd $od +mix release fireguard