From bf7e8f2852c4eb14bc7f6c642cd00b5e72cdfa42 Mon Sep 17 00:00:00 2001 From: Jamil Bou Kheir Date: Sun, 1 Nov 2020 20:33:49 -0600 Subject: [PATCH] build from workflow --- .github/workflows/main.yml | 6 ++++- pkg/Dockerfile | 48 ++++++++++++++++++++++++++++++--- scripts/build.sh | 54 ------------------------------------- scripts/install_runtimes.sh | 21 --------------- 4 files changed, 50 insertions(+), 79 deletions(-) delete mode 100755 scripts/build.sh delete mode 100755 scripts/install_runtimes.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0947199a2..9cef5728c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -69,7 +69,11 @@ jobs: elixir-version: "1.11.1" otp-version: "23.1.1" - name: Build packages - run: which docker + run: | + short_sha=$(git rev-parse --short HEAD) + docker build -t fireguard:$short_sha -f pkg/Dockerfile . + cid=$(docker create fireguard:$short_sha) + docker cp ${cid}:/build/fireguard_0.1.0-1_amd64.deb . - name: upload package uses: actions/upload-artifact@v2 with: diff --git a/pkg/Dockerfile b/pkg/Dockerfile index 7e5e286a4..3db34e4b3 100644 --- a/pkg/Dockerfile +++ b/pkg/Dockerfile @@ -1,11 +1,22 @@ # This Dockerfile builds release packages -FROM ubuntu:20.04 +FROM hexpm/elixir:1.11.1-erlang-23.1.1-ubuntu-focal-20200703 AS build # Setup to run build script ENV DEBIAN_FRONTEND noninteractive RUN apt-get update -q && \ apt-get install -y --no-install-recommends \ ca-certificates \ + build-essential \ + git \ + dpkg-dev \ + libssl-dev \ + automake \ + gnupg \ + curl \ + autoconf \ + libncurses5-dev \ + unzip \ + zlib1g-dev \ locales && \ apt-get clean && \ rm -rf /tmp/* /var/tmp/* @@ -15,6 +26,37 @@ ENV LANG en_US.UTF-8 ENV LANGUAGE en_US:en ENV LC_ALL en_US.UTF-8 -WORKDIR /app +RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - +RUN apt-get install nodejs + +ENV MIX_ENV prod +WORKDIR /build + +RUN mix local.hex --force && \ + mix local.rebar --force +COPY mix.exs mix.lock ./ +COPY config config +COPY apps/fg_http/mix.exs ./apps/fg_http/ +COPY apps/fg_wall/mix.exs ./apps/fg_wall/ +COPY apps/fg_vpn/mix.exs ./apps/fg_vpn/ +RUN mix do deps.get, deps.compile + +COPY apps/fg_http/assets/package.json apps/fg_http/assets/package-lock.json ./apps/fg_http/assets/ +RUN cd apps/fg_http/assets && npm ci --progress=false --no-audit --loglevel=error +COPY apps/fg_http/priv apps/fg_http/priv +COPY apps/fg_http/assets apps/fg_http/assets +RUN npm run --prefix ./apps/fg_http/assets deploy && \ + cd apps/fg_http && mix phx.digest + COPY . . -RUN ./scripts/build.sh +RUN mix release fireguard + +RUN mkdir -p pkg/debian/opt +RUN mv _build/prod/rel/fireguard pkg/debian/opt/fireguard + +ENV DATABASE_URL ecto://dummy@localhost/dummy +ENV SECRET_KEY_BASE dummy +RUN ./pkg/debian/opt/fireguard/bin/fireguard eval 'IO.puts "Hello World!"' + +RUN cd pkg && dpkg-deb --build debian +RUN mv pkg/debian.deb fireguard_0.1.0-1_amd64.deb diff --git a/scripts/build.sh b/scripts/build.sh deleted file mode 100755 index 4f37f6987..000000000 --- a/scripts/build.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env bash -set -e - -export root=`pwd` - -apt-get update -q && \ - apt-get install -y --no-install-recommends \ - build-essential \ - git \ - curl \ - libssl-dev \ - automake \ - lintian \ - dpkg-dev \ - gnupg \ - autoconf \ - libncurses5-dev \ - unzip \ - zlib1g-dev - -# Only install runtimes if not running in Github action -if [ -z "${CI+1}" ]; then - bash scripts/install_runtimes.sh -fi - -# Set build env vars -export MIX_ENV=prod - -# Install dependencies -mix local.hex --force -mix local.rebar --force -mix do deps.get, deps.compile - -# Compile assets -cd $root/apps/fg_http/assets && npm i --progress=false --no-audit --loglevel=error -cd $root/apps/fg_http/assets && npm run deploy && cd .. && mix phx.digest - -# Build the release -cd $root && mix release fireguard - -# Move release for packaging -mv ./_build/prod/rel/fireguard ./pkg/debian/opt/fireguard - -# Smoke test -export DATABASE_URL=ecto://dummy@localhost/dummy -export SECRET_KEY_BASE=dummy -./pkg/debian/opt/fireguard/bin/fireguard eval 'IO.puts "hello world"' - -# Build package -cd $root/pkg && dpkg-deb --build debian -mv pkg/debian.deb fireguard_0.1.0-1_amd64.deb - -# TODO: This reports too many issues... :-( -# RUN lintian fireguard_0.1.0-1_amd64.deb diff --git a/scripts/install_runtimes.sh b/scripts/install_runtimes.sh deleted file mode 100755 index 0e217c77f..000000000 --- a/scripts/install_runtimes.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env sh -set -e - -git clone --depth 1 https://github.com/asdf-vm/asdf.git $HOME/.asdf -export PATH="${PATH}:${HOME}/.asdf/shims:${HOME}/.asdf/bin" -echo '. $HOME/.asdf/asdf.sh' >> $HOME/.bashrc -echo '. $HOME/.asdf/asdf.sh' >> $HOME/.bash_profile - -bash $HOME/.asdf/asdf.sh - -# Install project runtimes -asdf plugin-add erlang && \ - asdf plugin-update erlang && \ - asdf plugin-add elixir && \ - asdf plugin-update elixir && \ - asdf plugin-add nodejs && \ - asdf plugin-update nodejs && \ - asdf plugin-add python && \ - asdf plugin-update python -bash -c '${ASDF_DATA_DIR:=$HOME/.asdf}/plugins/nodejs/bin/import-release-team-keyring' -asdf install