From 49006499083e6c45d9134ea2747e3d0d27f13dfa Mon Sep 17 00:00:00 2001 From: Brandon Skrtich Date: Thu, 2 Jun 2022 05:55:01 +0000 Subject: [PATCH] feat: Updates to docker file and gh action * Clean up Dockerfile * Add health check to Dockerfile * Update gh action versions --- .github/workflows/docker-build.yml | 36 +++++++++++++++++------------- Dockerfile | 18 +++++++++++---- readme.md | 9 ++++---- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 8b678324..80439648 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -3,8 +3,15 @@ name: Build and Push Docker Image on: + # Allows you to run workflow manually from Actions tab + workflow_dispatch: + inputs: + tags: + description: 'Docker Tag' + required: true + default: 'latest' push: - branches: [master] + branches: [main,master] tags: - 'v*.*.*' # Only build when files in these directories have been changed @@ -13,8 +20,6 @@ on: - server/** - index.js - package.json - # Allows you to run workflow manually from Actions tab - workflow_dispatch: jobs: build: @@ -23,24 +28,25 @@ jobs: steps: - name: Check out - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Docker meta id: meta - uses: docker/metadata-action@v3 + uses: docker/metadata-action@v4 with: images: advplyr/audiobookshelf,ghcr.io/${{ github.repository_owner }}/audiobookshelf tags: | type=edge,branch=master type=semver,pattern={{version}} + - name: Setup QEMU - uses: docker/setup-qemu-action@v1 + uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - + uses: docker/setup-buildx-action@v2 + - name: Cache Docker layers - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: /tmp/.buildx-cache key: ${{ runner.os }}-buildx-${{ github.sha }} @@ -48,28 +54,28 @@ jobs: ${{ runner.os }}-buildx- - name: Login to Dockerhub - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }} - + - name: Login to ghcr - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GHCR_PASSWORD }} - name: Build image - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v3 with: - tags: ${{ steps.meta.outputs.tags }} + tags: ${{ github.event.inputs.tags || steps.meta.outputs.tags }} context: . platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max - + - name: Move cache run: | rm -rf /tmp/.buildx-cache diff --git a/Dockerfile b/Dockerfile index bf51a6a2..43ee4eb4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,13 +7,23 @@ RUN npm run generate ### STAGE 1: Build server ### FROM node:16-alpine -RUN apk update && apk add --no-cache --update ffmpeg ENV NODE_ENV=production +RUN apk update && \ + apk add --no-cache --update \ + curl \ + tzdata \ + ffmpeg + COPY --from=build /client/dist /client/dist -COPY index.js index.js -COPY package-lock.json package-lock.json -COPY package.json package.json +COPY index.js package* / COPY server server + RUN npm ci --only=production + EXPOSE 80 +HEALTHCHECK \ + --interval=30s \ + --timeout=3s \ + --start-period=10s \ + CMD curl -f http://127.0.0.1/ping || exit 1 CMD ["npm", "start"] diff --git a/readme.md b/readme.md index a70b6d9d..88247a32 100644 --- a/readme.md +++ b/readme.md @@ -69,7 +69,7 @@ docker run -d \ -e AUDIOBOOKSHELF_GID=100 \ -p 13378:80 \ -v :/audiobooks \ - -v :/podcasts \ + -v :/podcasts \ -v :/config \ -v :/metadata \ --name audiobookshelf \ @@ -90,6 +90,7 @@ docker start audiobookshelf ### docker-compose.yml ### services: audiobookshelf: + container_name: audiobookshelf image: ghcr.io/advplyr/audiobookshelf:latest environment: - AUDIOBOOKSHELF_UID=99 @@ -97,8 +98,8 @@ services: ports: - 13378:80 volumes: - - :/audiobooks - - :/podcasts + - :/audiobooks + - :/podcasts - :/config - :/metadata ``` @@ -195,7 +196,7 @@ server proxy_redirect http:// https://; } } -``` +``` ### Apache Reverse Proxy