diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 0000000..fdcd174 --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,66 @@ +# Script taken from +# https://github.com/darless1/gollum/blob/docker/.github/workflows/build-and-test.yml +# MIT License + +name: Build and Test Docker +on: [push, pull_request] + +env: + CI_IMAGE: ${{ secrets.DOCKER_HUB_USERNAME }}/w2wiki:dev-${{ github.sha }} + DEPLOY_IMAGE: ${{ secrets.DOCKER_HUB_USERNAME }}/w2wiki:latest + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Check Out Repo + uses: actions/checkout@v2 + - name: Login + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + - name: Cache docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./Containerfile + builder: ${{ steps.buildx.outputs.name }} + push: true + tags: ${{ env.CI_IMAGE }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} + + deploy-on-master: + runs-on: ubuntu-latest + if: ${{ github.ref == 'refs/heads/master' }} + needs: build + steps: + - name: Login + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Pull + run: docker pull ${{ env.CI_IMAGE }} + - name: Tag + run: docker tag ${{ env.CI_IMAGE }} ${{ env.DEPLOY_IMAGE }} + - name: Push + run: docker push ${{ env.DEPLOY_IMAGE }} + diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..9e5de94 --- /dev/null +++ b/Containerfile @@ -0,0 +1,23 @@ +FROM php:7-apache + +RUN docker-php-ext-install exif + +RUN set -eux; \ + \ + apt-get update; \ + apt-get install -y --no-install-recommends git; \ + rm -rf /var/lib/apt/lists/*; \ + apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false + +COPY --chown=www-data:www-data . /var/www/html + +RUN set -eux; \ + \ + sed -i "s/BASE_PATH \\. //" /var/www/html/config.php ;\ + sed -i "s/'GIT_COMMIT_ENABLED', false/'GIT_COMMIT_ENABLED', true/" /var/www/html/config.php ;\ + echo "" > /etc/apache2/mods-enabled/alias.conf + +VOLUME /pages +EXPOSE 80 + +CMD /var/www/html/container-start.sh diff --git a/container-start.sh b/container-start.sh new file mode 100755 index 0000000..5348d80 --- /dev/null +++ b/container-start.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -e + +# on empty volume copy default pages +if ! test -f /pages/Home.md ; then + cp /var/www/html/pages/* /pages + + ( + cd /pages + git init + git config user.email "w2wiki@w2wiki" + git config user.name "w2wiki" + + git add -A . + git commit -m "Init with default pages" + ) +fi + +mkdir -p /pages/images +chown -R www-data:www-data /pages + +exec apache2-foreground "$@"