Skip to content

Commit

Permalink
Merge pull request #631 from rare-magma/add-alpine-docker-image
Browse files Browse the repository at this point in the history
Add alpine docker image version
  • Loading branch information
sstidl authored Aug 14, 2024
2 parents 3ae0e9e + 76bb7de commit 79436f0
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 10 deletions.
25 changes: 19 additions & 6 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ env:
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- dockerfile: ./Dockerfile
image: ghcr.io/${{ github.repository }}
flavour: ""
- dockerfile: ./Dockerfile.alpine
image: ghcr.io/${{ github.repository }}
flavour: "-alpine"
permissions:
contents: read
packages: write
Expand Down Expand Up @@ -69,14 +79,16 @@ jobs:
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
images: ${{ matrix.image }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=ref,event=branch,suffix=${{ matrix.flavour }}
type=ref,event=pr,suffix=${{ matrix.flavour }}
# set latest tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest${{ matrix.flavour }},enable={{is_default_branch}}
type=semver,pattern={{version}}${{ matrix.flavour }}
type=semver,pattern={{major}}${{ matrix.flavour }}
type=semver,pattern={{major}}.{{minor}}${{ matrix.flavour }}
type=semver,pattern={{major}}.{{minor}}.{{patch}}${{ matrix.flavour }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
Expand All @@ -85,6 +97,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
file: ${{ matrix.dockerfile }}
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
Expand Down
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM php:8-apache

# Install extensions
RUN apt-get update && apt-get install -y \
RUN apt-get update && apt-get install -y --no-install-recommends \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
Expand All @@ -10,6 +10,12 @@ RUN apt-get update && apt-get install -y \
&& docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install -j$(nproc) gd pdo pdo_mysql pdo_pgsql pgsql \
&& rm -f /usr/src/php.tar.xz /usr/src/php.tar.xz.asc \
&& apt-get remove -y libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libpq-dev \
&& apt autoremove -y \
&& rm -rf /var/lib/apt/lists/*

# Prepare files and folders
Expand Down
59 changes: 59 additions & 0 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
FROM php:8-alpine

# Install extensions
RUN apk add --quiet --no-cache \
bash \
apache2 \
apache2-ssl \
php83-apache2 \
php83-ctype \
php83-openssl \
freetype-dev \
libjpeg-turbo-dev \
libpng-dev \
libpq-dev \
&& docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install -j$(nproc) gd pdo pdo_mysql pdo_pgsql pgsql \
&& rm -f /usr/src/php.tar.xz /usr/src/php.tar.xz.asc \
&& apk del --quiet --no-cache \
freetype-dev \
libjpeg-turbo-dev \
libpng-dev \
libpq-dev

RUN ln -sf /dev/stdout /var/log/apache2/access.log && \
ln -sf /dev/stderr /var/log/apache2/error.log

# Prepare files and folders
RUN mkdir -p /speedtest/

# Copy sources
COPY backend/ /speedtest/backend

COPY results/*.php /speedtest/results/
COPY results/*.ttf /speedtest/results/

COPY *.js /speedtest/
COPY favicon.ico /speedtest/

COPY docker/servers.json /servers.json

COPY docker/*.php /speedtest/
COPY docker/entrypoint.sh /

# Prepare default environment variables
ENV TITLE=LibreSpeed
ENV MODE=standalone
ENV PASSWORD=password
ENV TELEMETRY=false
ENV ENABLE_ID_OBFUSCATION=false
ENV REDACT_IP_ADDRESSES=false
ENV WEBPORT=80

# https://httpd.apache.org/docs/2.4/stopping.html#gracefulstop
STOPSIGNAL SIGWINCH

# Final touches
EXPOSE 80
CMD ["bash", "/entrypoint.sh"]
19 changes: 16 additions & 3 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ cp /speedtest/*.js /var/www/html/
# Copy favicon
cp /speedtest/favicon.ico /var/www/html/

# Set custom webroot on alpine
if [ -f /etc/alpine-release ]; then
sed -i "s#\"/var/www/localhost/htdocs\"#\"/var/www/html\"#g" /etc/apache2/httpd.conf
fi

# Set up backend side for standlone modes
if [[ "$MODE" == "standalone" || "$MODE" == "dual" ]]; then
cp -r /speedtest/backend/ /var/www/html/backend
Expand Down Expand Up @@ -79,11 +84,19 @@ chown -R www-data /var/www/html/*

# Allow selection of Apache port for network_mode: host
if [ "$WEBPORT" != "80" ]; then
sed -i "s/^Listen 80\$/Listen $WEBPORT/g" /etc/apache2/ports.conf
sed -i "s/*:80>/*:$WEBPORT>/g" /etc/apache2/sites-available/000-default.conf
if [ -f /etc/alpine-release ]; then
sed -i "s/^Listen 80\$/Listen $WEBPORT/g" /etc/apache2/httpd.conf
else
sed -i "s/^Listen 80\$/Listen $WEBPORT/g" /etc/apache2/ports.conf
sed -i "s/*:80>/*:$WEBPORT>/g" /etc/apache2/sites-available/000-default.conf
fi
fi

echo "Done, Starting APACHE"

# This runs apache
exec apache2-foreground
if [ -f /etc/alpine-release ]; then
exec httpd -DFOREGROUND
else
exec apache2-foreground
fi

0 comments on commit 79436f0

Please sign in to comment.