diff --git a/.github/workflows/docker-image-push.yml b/.github/workflows/docker-image-push.yml index 4bf3907..03462b2 100644 --- a/.github/workflows/docker-image-push.yml +++ b/.github/workflows/docker-image-push.yml @@ -1,6 +1,8 @@ -name: Build (and push) multi-arch Docker image +name: Build and push multi-arch Docker image -on: [push, pull_request] +on: + release: + types: [published] jobs: build: @@ -16,46 +18,23 @@ jobs: uses: actions/checkout@v1 - name: Docker login - if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }} env: DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} run: echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin docker.io - - name: Setup buildx - run: | - sudo apt-get update - sudo apt-get install -y qemu-user-static - docker buildx create --use + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + with: + install: true - name: Build Docker image env: PLATFORMS: linux/amd64,linux/arm64/v8,linux/arm/v7 DOCKER_REPOSITORY: thelounge/thelounge - run: | - TAG="$(git rev-parse --short HEAD)" - EXTRA_ARG=() - # Only push on regular push (!= pull_request) - if [ "${GITHUB_EVENT_NAME}" = "push" ] && grep -q "^refs/tags/" <<< "${GITHUB_REF}"; then - EXTRA_ARG+=("--push") - VERSION="$(git describe --exact-match --tags)" - TAG="${VERSION}" - MAJOR_TAG="$(echo "$VERSION" | sed -nre 's/^([0-9]+).*/\1/p')" - LATEST_TAG="latest" - if grep -q "^alpine/" <<< "${{ matrix.dockerfile }}"; then - TAG="${TAG}-alpine" - MAJOR_TAG="${MAJOR_TAG}-alpine" - LATEST_TAG="alpine" - fi - # If not a pre-release push LATEST_TAG & MAJOR_TAG - if grep -qE "^[0-9]*\.[0-9]*\.[0-9]*$" <<< "${VERSION}"; then - EXTRA_ARG+=("--tag" "${DOCKER_REPOSITORY}:${LATEST_TAG}") - EXTRA_ARG+=("--tag" "${DOCKER_REPOSITORY}:${MAJOR_TAG}") - fi - fi - docker buildx build \ - --platform "${PLATFORMS}" \ - --tag "${DOCKER_REPOSITORY}:${TAG}" \ - "${EXTRA_ARG[@]}" \ - --file "${{ matrix.dockerfile }}" \ - . + DOCKERFILE: ${{ matrix.dockerfile }} + run: ./scripts/build-and-push.sh diff --git a/.github/workflows/docker-image-test.yml b/.github/workflows/docker-image-test.yml index c0653c7..c560386 100644 --- a/.github/workflows/docker-image-test.yml +++ b/.github/workflows/docker-image-test.yml @@ -7,32 +7,53 @@ jobs: name: Build runs-on: ubuntu-latest strategy: + fail-fast: false matrix: + platform: [linux/amd64, linux/arm64/v8, linux/arm/v7] dockerfile: [Dockerfile, alpine/Dockerfile] steps: - name: Set env run: echo "mount_dir=$(mktemp -d)" >> $GITHUB_ENV - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v2 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + with: + install: true - name: Build Docker image - run: docker build -t thelounge -f ${{ matrix.dockerfile }} . + run: docker build --platform ${{ matrix.platform }} --load -t thelounge -f ${{ matrix.dockerfile }} . - name: Start Docker container - run: docker run --user "$UID" -v "${mount_dir}:/var/opt/thelounge" -d -p 9001:9000 --name thelounge thelounge + run: docker run --platform ${{ matrix.platform }} --user "$UID" -v "${mount_dir}:/var/opt/thelounge" -d -p 9001:9000 --name thelounge thelounge - name: Check TheLounge version run: docker exec thelounge thelounge --version | grep --color=never -E "^v[0-9]\.[0-9]\.[0-9]" | cut -c 2- | grep -f /dev/stdin ${{ matrix.dockerfile }} - - name: Wait for server to (hopefully) start - run: sleep 3 - - name: Check HTML output - run: curl -sL localhost:9001 | grep "The Lounge" + run: | + # Retry Wait for server to start. + for i in {1..10}; do + (curl -sL localhost:9001 | grep "The Lounge") && s=0 && break || s=$? && sleep 1; + done + exit $s + + - name: Check for no ERROR logs + run: docker logs thelounge | grep "\[ERROR\]" && exit 1 || exit 0 - name: Check for config.js to be created in the mounted host system directory run: stat "${mount_dir}/config.js" + - name: Container context + if: always() + run: docker exec thelounge uname -a + - name: Logs + if: always() run: docker logs thelounge diff --git a/Dockerfile b/Dockerfile index 66d98c9..fdc79d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,5 +16,11 @@ COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh # Install thelounge. ARG THELOUNGE_VERSION=4.3.0 -RUN yarn --non-interactive --frozen-lockfile global add thelounge@${THELOUNGE_VERSION} && \ - yarn --non-interactive cache clean +RUN apt update && apt install -y python2 g++ make && \ + ln -s $(which python2) /usr/bin/python && \ + yarn --non-interactive --frozen-lockfile global add thelounge@${THELOUNGE_VERSION} && \ + yarn --non-interactive cache clean && \ + apt remove -y python2 g++ make && \ + apt autoremove -y && \ + rm -rf /var/lib/apt/lists/* && \ + rm -f /usr/bin/python diff --git a/alpine/Dockerfile b/alpine/Dockerfile index 4b901d5..f632e22 100644 --- a/alpine/Dockerfile +++ b/alpine/Dockerfile @@ -16,7 +16,7 @@ COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh # Install thelounge. ARG THELOUNGE_VERSION=4.3.0 -RUN apk --update --no-cache add python3 build-base && \ +RUN apk --update --no-cache add python2 build-base && \ yarn --non-interactive --frozen-lockfile global add thelounge@${THELOUNGE_VERSION} && \ yarn --non-interactive cache clean && \ - apk del python3 build-base + apk del python2 build-base diff --git a/alpine/docker-entrypoint.sh b/alpine/docker-entrypoint.sh deleted file mode 100755 index efbd313..0000000 --- a/alpine/docker-entrypoint.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -if [ "$1" = "thelounge" ] && [ "$(id -u)" = '0' ]; then - find "${THELOUNGE_HOME}" \! -user node -exec chown node '{}' + - exec su node -c "$*" -fi - -exec "$@" diff --git a/scripts/build-and-push.sh b/scripts/build-and-push.sh new file mode 100755 index 0000000..ce242e3 --- /dev/null +++ b/scripts/build-and-push.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# Script executed by GitHub actions. + +set -euo pipefail + +VERSION="$GITHUB_REF" +TAG="$VERSION" +MAJOR_TAG="$(sed -nre 's/^([0-9]+).*/\1/p' <<< "$VERSION")" +LATEST_TAG="latest" + +if grep -q "^alpine/" <<< "${DOCKERFILE}"; then + TAG="${VERSION}-alpine" + MAJOR_TAG="${MAJOR_TAG}-alpine" + LATEST_TAG="alpine" +fi + +# If not a pre-release push LATEST_TAG & MAJOR_TAG +if grep -qE "^[0-9]*\.[0-9]*\.[0-9]*$" <<< "${VERSION}"; then + EXTRA_ARG+=("--tag" "${DOCKER_REPOSITORY}:${LATEST_TAG}") + EXTRA_ARG+=("--tag" "${DOCKER_REPOSITORY}:${MAJOR_TAG}") +fi + +docker buildx build \ + --push \ + --platform "${PLATFORMS}" \ + --tag "${DOCKER_REPOSITORY}:${TAG}" \ + "${EXTRA_ARG[@]}" \ + --file "${DOCKERFILE}" \ + . diff --git a/update-version.sh b/scripts/update-version.sh similarity index 100% rename from update-version.sh rename to scripts/update-version.sh