Skip to content

Commit

Permalink
fix node-sqlite3 dependency in ARM builds (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
williamboman authored Nov 23, 2021
1 parent 8f98fff commit 4d09668
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 54 deletions.
49 changes: 14 additions & 35 deletions .github/workflows/docker-image-push.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
35 changes: 28 additions & 7 deletions .github/workflows/docker-image-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<title>The Lounge</title>"
run: |
# Retry Wait for server to start.
for i in {1..10}; do
(curl -sL localhost:9001 | grep "<title>The Lounge</title>") && 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
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 0 additions & 8 deletions alpine/docker-entrypoint.sh

This file was deleted.

29 changes: 29 additions & 0 deletions scripts/build-and-push.sh
Original file line number Diff line number Diff line change
@@ -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}" \
.
File renamed without changes.

0 comments on commit 4d09668

Please sign in to comment.