From b18a9dab50cc7635a02e1b3ce4f9d4901d70c89d Mon Sep 17 00:00:00 2001 From: arbulu89 Date: Fri, 22 Apr 2022 11:39:53 +0200 Subject: [PATCH 1/6] Update suse packaging delivery files --- packaging/suse/Dockerfile | 54 ++++++++++++++++++++++++++------------- packaging/suse/_service | 4 +++ 2 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 packaging/suse/_service diff --git a/packaging/suse/Dockerfile b/packaging/suse/Dockerfile index 760521a193..227999afcc 100644 --- a/packaging/suse/Dockerfile +++ b/packaging/suse/Dockerfile @@ -1,24 +1,42 @@ -FROM registry.suse.com/bci/nodejs:16 AS assets-build -ADD assets /build/assets -WORKDIR /build/assets -RUN npm install +#!BuildTag: trento/trento-web:latest +#!BuildTag: trento/trento-web:1.0.0 +#!BuildTag: trento/trento-web:1.0.0-build%RELEASE% +#!UseOBSRepositories -FROM registry.suse.com/bci/bci-base:15.3 AS elixir-build -RUN zypper -n addrepo https://download.opensuse.org/repositories/devel:/languages:/erlang/SLE_15_SP3/devel:languages:erlang.repo -RUN zypper -n --gpg-auto-import-keys ref -s -RUN zypper -n in elixir -ADD . /build -COPY --from=assets-build /build/assets /build/assets -WORKDIR /build -ENV MIX_ENV=dev -RUN mix local.rebar --force \ - && mix local.hex --force \ - && mix deps.get -RUN mix release +FROM bci/nodejs:16 AS assets-build +ADD web.tar.gz /build/ +WORKDIR /build/web/assets +RUN npm run tailwind:build +RUN npm run build +FROM suse/sle15:15.3 AS release +# FLAVOR defined in prjconf, e.g. +# BuildFlags: dockerarg:FLAVOR=Community +ARG FLAVOR=Community +# # Workaround for https://github.com/openSUSE/obs-build/issues/487 +RUN zypper --non-interactive in sles-release +RUN zypper -n in elixir elixir-hex erlang-rebar3 +COPY --from=assets-build /build /build +WORKDIR /build/web/ +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 +ENV MIX_ENV=prod +ENV MIX_HOME=/usr/bin +ENV FLAVOR="$FLAVOR" +RUN mix phx.digest +RUN mix release -FROM registry.suse.com/bci/bci-base:15.3 AS trento +FROM suse/sle15:15.3 AS trento +# Define labels according to https://en.opensuse.org/Building_derived_containers +# labelprefix=com.suse.trento +LABEL org.opencontainers.image.source="https://github.com/trento-project/web" +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 +# tar is required by kubectl cp +RUN zypper -n in tar WORKDIR /app -COPY --from=elixir-build /build/_build/dev/rel/trento/ . +COPY --from=release /build/web/_build/prod/rel/trento . EXPOSE 4000/tcp ENTRYPOINT ["/app/bin/trento"] diff --git a/packaging/suse/_service b/packaging/suse/_service new file mode 100644 index 0000000000..56ac46b6d5 --- /dev/null +++ b/packaging/suse/_service @@ -0,0 +1,4 @@ + + + + From a8009e2c61315d705479c57e8a288d4c6afe05be Mon Sep 17 00:00:00 2001 From: arbulu89 Date: Fri, 22 Apr 2022 12:38:26 +0200 Subject: [PATCH 2/6] Add CI for container delivery in suse obs --- .github/workflows/ci.yaml | 66 +++++++++++++++++++++++++++++++++++- hack/get_version_from_git.sh | 14 ++++++++ packaging/suse/Dockerfile | 4 +-- 3 files changed, 81 insertions(+), 3 deletions(-) create mode 100755 hack/get_version_from_git.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 06916ac1c6..c6c7b9a75a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -54,7 +54,7 @@ jobs: mix local.rebar --force mix local.hex --force mix deps.get - mix deps.compile --warnings-as-errors + mix deps.compile --warnings-as-errors mix dialyzer --plt static-code-analysis: @@ -291,3 +291,67 @@ jobs: labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max + + obs-commit: + name: Commit the project on OBS + runs-on: ubuntu-20.04 + #if: github.event_name == 'release' || (github.event_name == 'push' && github.ref_name == 'main') || github.event_name == 'workflow_dispatch' + #needs: [deps, static-code-analysis, test, test-e2e] + needs: [deps] + container: + image: ghcr.io/trento-project/continuous-delivery:master + env: + GITHUB_OAUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DEST_FOLDER: "/tmp/osc_project" + NAME: trento-web-image + OBS_USER: ${{ secrets.OBS_USER }} + OBS_PASS: ${{ secrets.OBS_PASS }} + OBS_PROJECT: ${{ secrets.OBS_PROJECT }} + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.9.1 + with: + access_token: ${{ github.token }} + + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Setup + run: | + ssl_verify=host zypper in -y wget unzip + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + + - name: Install assets + run: cd assets && npm install + + - name: Get mix deps + run: mix local.hex --force && mix deps.clean --all && mix deps.get + + - name: Set version + run: | + VERSION=$(./hack/get_version_from_git.sh) + sed -i 's~%%VERSION%%~'"${VERSION}"'~' packaging/suse/Dockerfile + + - name: Configure OSC + # OSC credentials must be configured beforehand as the HOME variables cannot be changed from /github/home + # that is used to run osc commands + run: | + /scripts/init_osc_creds.sh + mkdir -p $HOME/.config/osc + cp /root/.config/osc/oscrc $HOME/.config/osc + + - name: Commit on OBS + run: | + OBS_PACKAGE=$OBS_PROJECT/$NAME + osc checkout $OBS_PACKAGE -o $DEST_FOLDER + cp -r packaging/suse/* $DEST_FOLDER + tar -zcvf $DEST_FOLDER/web.tar.gz --exclude=.git ./ + cd $DEST_FOLDER + osc ar + osc commit -m "New development version of $NAME released" diff --git a/hack/get_version_from_git.sh b/hack/get_version_from_git.sh new file mode 100755 index 0000000000..6fee3489dc --- /dev/null +++ b/hack/get_version_from_git.sh @@ -0,0 +1,14 @@ +#!/bin/sh +TAG=$( git tag | grep -E "[0-9]\.[0-9]\.[0-9]" | sort -rn | head -n1 ) + +if [ -n "${TAG}" ]; then + COMMITS_SINCE_TAG=$(git rev-list "${TAG}".. --count) + if [ "${COMMITS_SINCE_TAG}" -gt 0 ]; then + COMMIT_SHA=$(git show -s --format=%ct.%h HEAD) + SUFFIX="+git.dev${COMMITS_SINCE_TAG}.${COMMIT_SHA}" + fi +else + TAG="0" +fi + +echo "${TAG}${SUFFIX}" diff --git a/packaging/suse/Dockerfile b/packaging/suse/Dockerfile index 227999afcc..0c652c2851 100644 --- a/packaging/suse/Dockerfile +++ b/packaging/suse/Dockerfile @@ -1,6 +1,6 @@ #!BuildTag: trento/trento-web:latest -#!BuildTag: trento/trento-web:1.0.0 -#!BuildTag: trento/trento-web:1.0.0-build%RELEASE% +#!BuildTag: trento/trento-web:%%VERSION%% +#!BuildTag: trento/trento-web:%%VERSION%%-build%RELEASE% #!UseOBSRepositories FROM bci/nodejs:16 AS assets-build From 2f3a309f83c019c469855d94c0124262ee97ba84 Mon Sep 17 00:00:00 2001 From: arbulu89 Date: Mon, 25 Apr 2022 10:15:45 +0200 Subject: [PATCH 3/6] Move Dockerfile to root folder --- .github/workflows/ci.yaml | 3 ++- Dockerfile | 48 ++++++++++++++++++++------------------- packaging/suse/Dockerfile | 42 ---------------------------------- 3 files changed, 27 insertions(+), 66 deletions(-) delete mode 100644 packaging/suse/Dockerfile diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c6c7b9a75a..900c8316ad 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -336,7 +336,7 @@ jobs: - name: Set version run: | VERSION=$(./hack/get_version_from_git.sh) - sed -i 's~%%VERSION%%~'"${VERSION}"'~' packaging/suse/Dockerfile + sed -i 's~%%VERSION%%~'"${VERSION}"'~' Dockerfile - name: Configure OSC # OSC credentials must be configured beforehand as the HOME variables cannot be changed from /github/home @@ -351,6 +351,7 @@ jobs: OBS_PACKAGE=$OBS_PROJECT/$NAME osc checkout $OBS_PACKAGE -o $DEST_FOLDER cp -r packaging/suse/* $DEST_FOLDER + cp Dockerfile $DEST_FOLDER tar -zcvf $DEST_FOLDER/web.tar.gz --exclude=.git ./ cd $DEST_FOLDER osc ar diff --git a/Dockerfile b/Dockerfile index e4c774ee64..0c652c2851 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,40 +1,42 @@ -FROM opensuse/leap AS elixir-build -ENV LANG en_US.UTF-8 -ENV LANGUAGE en_US:en -ENV LC_ALL en_US.UTF-8 -RUN zypper -n addrepo https://download.opensuse.org/repositories/devel:/languages:/erlang/SLE_15_SP3/devel:languages:erlang.repo -RUN zypper -n --gpg-auto-import-keys ref -s -RUN zypper -n in elixir -COPY . /build -WORKDIR /build -ENV MIX_ENV=prod -RUN mix local.rebar --force \ - && mix local.hex --force \ - && mix deps.get - +#!BuildTag: trento/trento-web:latest +#!BuildTag: trento/trento-web:%%VERSION%% +#!BuildTag: trento/trento-web:%%VERSION%%-build%RELEASE% +#!UseOBSRepositories -FROM registry.suse.com/bci/nodejs:16 AS assets-build -COPY --from=elixir-build /build /build -WORKDIR /build/assets -RUN npm install +FROM bci/nodejs:16 AS assets-build +ADD web.tar.gz /build/ +WORKDIR /build/web/assets RUN npm run tailwind:build RUN npm run build -FROM elixir-build AS release +FROM suse/sle15:15.3 AS release +# FLAVOR defined in prjconf, e.g. +# BuildFlags: dockerarg:FLAVOR=Community +ARG FLAVOR=Community +# # Workaround for https://github.com/openSUSE/obs-build/issues/487 +RUN zypper --non-interactive in sles-release +RUN zypper -n in elixir elixir-hex erlang-rebar3 COPY --from=assets-build /build /build -WORKDIR /build +WORKDIR /build/web/ +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 ENV MIX_ENV=prod +ENV MIX_HOME=/usr/bin +ENV FLAVOR="$FLAVOR" RUN mix phx.digest RUN mix release - -FROM registry.suse.com/bci/bci-base:15.3 AS trento +FROM suse/sle15:15.3 AS trento +# Define labels according to https://en.opensuse.org/Building_derived_containers +# labelprefix=com.suse.trento +LABEL org.opencontainers.image.source="https://github.com/trento-project/web" ENV LANG en_US.UTF-8 ENV LANGUAGE en_US:en ENV LC_ALL en_US.UTF-8 # tar is required by kubectl cp RUN zypper -n in tar WORKDIR /app -COPY --from=release /build/_build/prod/rel/trento . +COPY --from=release /build/web/_build/prod/rel/trento . EXPOSE 4000/tcp ENTRYPOINT ["/app/bin/trento"] diff --git a/packaging/suse/Dockerfile b/packaging/suse/Dockerfile deleted file mode 100644 index 0c652c2851..0000000000 --- a/packaging/suse/Dockerfile +++ /dev/null @@ -1,42 +0,0 @@ -#!BuildTag: trento/trento-web:latest -#!BuildTag: trento/trento-web:%%VERSION%% -#!BuildTag: trento/trento-web:%%VERSION%%-build%RELEASE% -#!UseOBSRepositories - -FROM bci/nodejs:16 AS assets-build -ADD web.tar.gz /build/ -WORKDIR /build/web/assets -RUN npm run tailwind:build -RUN npm run build - -FROM suse/sle15:15.3 AS release -# FLAVOR defined in prjconf, e.g. -# BuildFlags: dockerarg:FLAVOR=Community -ARG FLAVOR=Community -# # Workaround for https://github.com/openSUSE/obs-build/issues/487 -RUN zypper --non-interactive in sles-release -RUN zypper -n in elixir elixir-hex erlang-rebar3 -COPY --from=assets-build /build /build -WORKDIR /build/web/ -ENV LANG en_US.UTF-8 -ENV LANGUAGE en_US:en -ENV LC_ALL en_US.UTF-8 -ENV MIX_ENV=prod -ENV MIX_HOME=/usr/bin -ENV FLAVOR="$FLAVOR" -RUN mix phx.digest -RUN mix release - -FROM suse/sle15:15.3 AS trento -# Define labels according to https://en.opensuse.org/Building_derived_containers -# labelprefix=com.suse.trento -LABEL org.opencontainers.image.source="https://github.com/trento-project/web" -ENV LANG en_US.UTF-8 -ENV LANGUAGE en_US:en -ENV LC_ALL en_US.UTF-8 -# tar is required by kubectl cp -RUN zypper -n in tar -WORKDIR /app -COPY --from=release /build/web/_build/prod/rel/trento . -EXPOSE 4000/tcp -ENTRYPOINT ["/app/bin/trento"] From fb4c925122fd31400553f4d62364e785f88ce566 Mon Sep 17 00:00:00 2001 From: arbulu89 Date: Mon, 25 Apr 2022 10:50:47 +0200 Subject: [PATCH 4/6] Prefix properly the tar files to add them in web folder --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 900c8316ad..454180b133 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -352,7 +352,7 @@ jobs: osc checkout $OBS_PACKAGE -o $DEST_FOLDER cp -r packaging/suse/* $DEST_FOLDER cp Dockerfile $DEST_FOLDER - tar -zcvf $DEST_FOLDER/web.tar.gz --exclude=.git ./ + tar --transform 's,^./,/web/,' -zcvf $DEST_FOLDER/web.tar.gz --exclude=.git ./* cd $DEST_FOLDER osc ar osc commit -m "New development version of $NAME released" From d6420570ad413ab06a52b382b7b0f01a03c6516b Mon Sep 17 00:00:00 2001 From: arbulu89 Date: Mon, 25 Apr 2022 11:35:38 +0200 Subject: [PATCH 5/6] Do not exclude .git folder on dependencies --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 454180b133..7eb83f926e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -352,7 +352,7 @@ jobs: osc checkout $OBS_PACKAGE -o $DEST_FOLDER cp -r packaging/suse/* $DEST_FOLDER cp Dockerfile $DEST_FOLDER - tar --transform 's,^./,/web/,' -zcvf $DEST_FOLDER/web.tar.gz --exclude=.git ./* + tar --transform 's,^./,/web/,' -zcvf $DEST_FOLDER/web.tar.gz --exclude=./.git ./* cd $DEST_FOLDER osc ar osc commit -m "New development version of $NAME released" From 5bcdab220a05255dd5593f0db8ad30050cd8791c Mon Sep 17 00:00:00 2001 From: arbulu89 Date: Mon, 25 Apr 2022 12:02:00 +0200 Subject: [PATCH 6/6] Uncomment needed lines in ci file --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7eb83f926e..20d32d13d1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -295,8 +295,8 @@ jobs: obs-commit: name: Commit the project on OBS runs-on: ubuntu-20.04 - #if: github.event_name == 'release' || (github.event_name == 'push' && github.ref_name == 'main') || github.event_name == 'workflow_dispatch' - #needs: [deps, static-code-analysis, test, test-e2e] + if: github.event_name == 'release' || (github.event_name == 'push' && github.ref_name == 'main') || github.event_name == 'workflow_dispatch' + needs: [deps, static-code-analysis, test, test-e2e] needs: [deps] container: image: ghcr.io/trento-project/continuous-delivery:master