From 71a01d060679c71b68a7e02b1d155b621e67f827 Mon Sep 17 00:00:00 2001 From: Keijo Raamat <49017291+keijoraamat@users.noreply.github.com> Date: Thu, 30 Sep 2021 16:02:17 +0300 Subject: [PATCH] Containerize proxy (#51) * Added dockerfile with all files and build pipeline * Trigger base image build on tool version change The release image from dockerfile should be builded when correct config files are present. --- .github/workflows/build_base_image.yml | 52 ++++++++++++++++++++++++++ Dockerfile.Erlang-ruby.base | 42 +++++++++++++++++++++ Dockerfile.release | 13 +++++++ 3 files changed, 107 insertions(+) create mode 100644 .github/workflows/build_base_image.yml create mode 100644 Dockerfile.Erlang-ruby.base create mode 100644 Dockerfile.release diff --git a/.github/workflows/build_base_image.yml b/.github/workflows/build_base_image.yml new file mode 100644 index 0000000..2ff800b --- /dev/null +++ b/.github/workflows/build_base_image.yml @@ -0,0 +1,52 @@ +name: build and push image + +on: + push: + paths: + - .tool-versions + +jobs: + + build: + + runs-on: ubuntu-20.04 + + steps: + + - uses: actions/checkout@v2 + + - name: Get versions + shell: python + run: | + import os + versions = {} + try: + with open(".tool-versions", "r") as f: + for line in f: + (key, val) = line.split() + versions[key] = val + except: + print("Something is off with getting the versions") + tag = "internetee/erlang-ruby:" + versions["erlang"] + "-" + versions["ruby"] + try: + f = open("TAG", "x") + f.write(tag) + except: + print("Something is not right with setting the tag") + finally: + f.close() + + - name: Set image tag" + run: | + echo "TAG=`cat TAG`" >> $GITHUB_ENV + + - name: Build image + run: | + docker build -t $TAG -f Dockerfile.Erlang-ruby.base . + + - name: Push image to Docker hub + env: + D_HUB_PASS: ${{ secrets.D_HUB_PASS}} + run: | + echo $D_HUB_PASS | docker login -u eiskra --password-stdin + docker push $TAG diff --git a/Dockerfile.Erlang-ruby.base b/Dockerfile.Erlang-ruby.base new file mode 100644 index 0000000..502bd99 --- /dev/null +++ b/Dockerfile.Erlang-ruby.base @@ -0,0 +1,42 @@ +FROM debian:buster-slim + +RUN apt-get update && apt-get install -y \ + wget \ + git \ + build-essential=* \ + libncurses5-dev=* \ + automake=* \ + autoconf=* \ + curl=* \ + ca-certificates=* \ + libssl-dev=* \ + libreadline-dev=* \ + libdpkg-perl=* \ + liberror-perl=* \ + libc6=* \ + libc-dev \ + perl=* \ + procps=* \ + inotify-tools=* \ + libssl1.1=* \ + perl-base=* \ + zlib1g-dev \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +RUN git clone https://github.com/asdf-vm/asdf.git "$HOME"/.asdf && \ + echo '. $HOME/.asdf/asdf.sh' >> "$HOME"/.bashrc && \ + echo '. $HOME/.asdf/asdf.sh' >> "$HOME"/.profile + +ENV PATH="${PATH}:/root/.asdf/shims:/root/.asdf/bin" + +RUN mkdir -p /opt/erlang/epp_proxy/release +WORKDIR /opt/erlang/epp_proxy + +COPY .tool-versions ./ +RUN asdf plugin-add erlang +RUN asdf install +RUN asdf global erlang $(grep erlang .tool-versions | cut -d' ' -f2) +RUN asdf plugin-add ruby +RUN asdf plugin-add rebar +RUN asdf install \ No newline at end of file diff --git a/Dockerfile.release b/Dockerfile.release new file mode 100644 index 0000000..c0d68f6 --- /dev/null +++ b/Dockerfile.release @@ -0,0 +1,13 @@ +FROM internetee/erlang-ruby:21.3.8-2.6.3 AS build +COPY . ./scr/ + +WORKDIR /opt/erlang/epp_proxy/scr + +RUN rebar3 as prod release + +FROM internetee/erlang-ruby:21.3.8-2.6.3 +LABEL org.opencontainers.image.source=https://github.com/internetee/epp_proxy + + +COPY --from=build /opt/erlang/epp_proxy/scr/_build/prod/rel/epp_proxy ./release +RUN ln -s /opt/erlang/epp_proxy/release/bin/epp_proxy ./epp_proxy