From 3d5dbed0b6376bf5708f6357c5658a900d1b1401 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sat, 29 Jan 2022 00:31:02 +0000 Subject: [PATCH 1/4] :whale: A GH action for building and publishing multi-arch Docker image to various registries --- .github/workflows/docker-build-publish.yml | 96 ++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 .github/workflows/docker-build-publish.yml diff --git a/.github/workflows/docker-build-publish.yml b/.github/workflows/docker-build-publish.yml new file mode 100644 index 00000000..3ecdeff7 --- /dev/null +++ b/.github/workflows/docker-build-publish.yml @@ -0,0 +1,96 @@ +# Builds, scans and tests the multi-architecture docker image +# Then releases it to the DockerHub, GHCR and Quay registries +name: 🐳 Build + Publish Multi-Platform Image + +on: + push: + branches: ['master'] + tags: [v*] + +env: + DH_IMAGE: ${{ secrets.DOCKER_REPO }} + GH_IMAGE: ${{ github.repository_owner }}/${{ github.event.repository.name }} + +jobs: + docker: + runs-on: ubuntu-latest + permissions: { contents: read, packages: write } + if: "!contains(github.event.head_commit.message, '[ci-skip]')" + + steps: + - name: 🛎️ Checkout Repo + uses: actions/checkout@v2 + + - name: 🔖 Get App Version + uses: tyankatsu0105/read-package-version-actions@v1 + id: package-version + + # - name: ✨ Validate Dockerfile + # uses: ghe-actions/dockerfile-validator@v1 + # with: + # dockerfile: 'Dockerfile' + # lint: 'hadolint' + + - name: 🗂️ Make Docker Meta + id: meta + uses: docker/metadata-action@v3 + with: + images: | + ${{ env.DH_IMAGE }} + ghcr.io/${{ env.GH_IMAGE }} + ${{ secrets.ACR_SERVER }}/${{ secrets.ACR_USERNAME }} + tags: | + type=ref,event=tag,prefix=release-,suffix={{tag}} + type=semver,pattern={{raw}},value=${{ steps.package-version.outputs.version }} + labels: | + maintainer=Lissy93 + org.opencontainers.image.title=Dashy + org.opencontainers.image.description=A self-hosted startpage for your server + org.opencontainers.image.documentation=https://dashy.to/docs + org.opencontainers.image.authors=Alicia Sykes + org.opencontainers.image.licenses=MIT + + - name: 🔧 Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: 🔧 Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: 🔑 Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: 🔑 Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: 🔑 Login to Azure Container Registry + uses: docker/login-action@v1 + with: + registry: ${{ secrets.ACR_SERVER }} + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_PASSWORD }} + + - name: ⚒️ Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64,linux/arm/v7 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + push: true + + - name: 💬 Set Docker Hub Description + uses: peter-evans/dockerhub-description@v2 + with: + repository: lissy93/dashy + readme-filepath: ./README.md + short-description: Dashy - A self-hosted start page for your server + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} From 3f1f284e63b0f6b5a6ea5c33c33710fd6b13e18a Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sat, 29 Jan 2022 00:31:41 +0000 Subject: [PATCH 2/4] :whale: New and improved multi-architecture Docker image --- Dockerfile | 48 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8328882f..b9aa13af 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,30 @@ -FROM node:lts-alpine3.14 +FROM node:14.17.5-alpine AS BUILD_IMAGE + +ARG TARGETPLATFORM +ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64} + +# Install additional tools needed on arm64 and armv7 +RUN \ + case "${TARGETPLATFORM}" in \ + 'linux/arm64') apk add --no-cache python make g++ ;; \ + 'linux/arm/v7') apk add --no-cache python make g++ ;; \ + esac + +# Create and set the working directory +WORKDIR /app + +# Install app dependencies +COPY package.json yarn.lock ./ +RUN yarn install --frozen-lockfile --network-timeout 1000000 + +# Copy over all project files and folders to the working directory +COPY . ./ + +# Build initial app for production +RUN yarn build + +# Build the final image +FROM node:14.17.5-alpine # Define some ENV Vars ENV PORT=80 \ @@ -8,24 +34,18 @@ ENV PORT=80 \ # Create and set the working directory WORKDIR ${DIRECTORY} -# Copy over both 'package.json' and 'package-lock.json' (if available) -COPY package*.json ./ -COPY yarn.lock ./ +# Install tini for initialization and tzdata for setting timezone +RUN apk add --no-cache tzdata tini -# Install project dependencies -RUN yarn +# Copy built application from build phase +COPY --from=BUILD_IMAGE /app ./ -# Copy over all project files and folders to the working directory -COPY . . - -# Build initial app for production -RUN yarn build +# Finally, run start command to serve up the built application +ENTRYPOINT [ "/sbin/tini", "--" ] +CMD [ "yarn", "build-and-start" ] # Expose given port EXPOSE ${PORT} -# Finally, run start command to serve up the built application -CMD [ "yarn", "build-and-start"] - # Run simple healthchecks every 5 mins, to check the Dashy's everythings great HEALTHCHECK --interval=5m --timeout=2s --start-period=30s CMD yarn health-check From fd2bf9c887019651638bebb401b74a3839606019 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sat, 29 Jan 2022 00:32:59 +0000 Subject: [PATCH 3/4] :wastebasket: Removes obsolete Docker actions --- .github/workflows/docker-image.yml | 96 ---------------------------- .github/workflows/docker-release.yml | 40 ------------ 2 files changed, 136 deletions(-) delete mode 100644 .github/workflows/docker-image.yml delete mode 100644 .github/workflows/docker-release.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml deleted file mode 100644 index ceb7e138..00000000 --- a/.github/workflows/docker-image.yml +++ /dev/null @@ -1,96 +0,0 @@ -# Builds, scans and tests the multi-architecture docker image -# Then releases it to the DockerHub, GHCR and Quay registries -name: 🐳 Build + Publish Multi-Platform Image - -on: - push: - branches: ['master'] - tags: [v*] - -env: - DH_IMAGE: ${{ secrets.DOCKER_REPO }} - GH_IMAGE: ${{ github.repository_owner }}/${{ github.event.repository.name }} - -jobs: - docker: - runs-on: ubuntu-latest - permissions: { contents: read, packages: write } - if: "!contains(github.event.head_commit.message, '[ci-skip]')" - - steps: - - name: 🛎️ Checkout Repo - uses: actions/checkout@v2 - - - name: 🔖 Get App Version - uses: tyankatsu0105/read-package-version-actions@v1 - id: package-version - - # - name: ✨ Validate Dockerfile - # uses: ghe-actions/dockerfile-validator@v1 - # with: - # dockerfile: 'Dockerfile' - # lint: 'hadolint' - - - name: 🗂️ Make Docker Meta - id: meta - uses: docker/metadata-action@v3 - with: - images: | - ${{ env.DH_IMAGE }} - ghcr.io/${{ env.GH_IMAGE }} - ${{ secrets.ACR_SERVER }}/${{ secrets.ACR_USERNAME }} - tags: | - type=ref,event=tag,prefix=release-,suffix={{tag}} - type=semver,pattern={{raw}},value=${{ steps.package-version.outputs.version }} - labels: | - maintainer=Lissy93 - org.opencontainers.image.title=Dashy - org.opencontainers.image.description=A self-hosted startpage for your server - org.opencontainers.image.documentation=https://dashy.to/docs - org.opencontainers.image.authors=Alicia Sykes - org.opencontainers.image.licenses=MIT - - - name: 🔧 Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: 🔧 Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: 🔑 Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: 🔑 Login to GitHub Container Registry - uses: docker/login-action@v1 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: 🔑 Login to Azure Container Registry - uses: docker/login-action@v1 - with: - registry: ${{ secrets.ACR_SERVER }} - username: ${{ secrets.ACR_USERNAME }} - password: ${{ secrets.ACR_PASSWORD }} - - - name: ⚒️ Build and push - uses: docker/build-push-action@v2 - with: - context: . - file: ./docker/Dockerfile-multi-arch - platforms: linux/amd64,linux/arm64,linux/arm/v7 - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - push: true - - - name: 💬 Set Docker Hub Description - uses: peter-evans/dockerhub-description@v2 - with: - repository: lissy93/dashy - readme-filepath: ./README.md - short-description: Dashy - A self-hosted start page for your server - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml deleted file mode 100644 index 523f7710..00000000 --- a/.github/workflows/docker-release.yml +++ /dev/null @@ -1,40 +0,0 @@ -# Test and build the Docker container after a release -# Then push it to GH container registry if all checks pass -name: Build & Publish Docker Image -on: - release: - types: [published] -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} -jobs: - build-and-push-image: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - # Get the code - - name: Checkout repository 🛎️ - uses: actions/checkout@v2 - # Log into ghcr.io - - name: Log in to the Container registry 🔑 - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - # Get release version, for Docker tag - - name: Extract metadata (tags, labels) for Docker 🗂️ - id: meta - uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - # Build the container, and push if successful - - name: Build and push Docker image ⚒️ - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} From aa1dc7b300fbd19d9f26d8e94bcaeb1c435bdfc4 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sat, 29 Jan 2022 00:45:17 +0000 Subject: [PATCH 4/4] :whale: Temporarily remove DockerHub description step --- .github/workflows/docker-build-publish.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/docker-build-publish.yml b/.github/workflows/docker-build-publish.yml index 3ecdeff7..dbf50bce 100644 --- a/.github/workflows/docker-build-publish.yml +++ b/.github/workflows/docker-build-publish.yml @@ -86,11 +86,11 @@ jobs: labels: ${{ steps.meta.outputs.labels }} push: true - - name: 💬 Set Docker Hub Description - uses: peter-evans/dockerhub-description@v2 - with: - repository: lissy93/dashy - readme-filepath: ./README.md - short-description: Dashy - A self-hosted start page for your server - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} + # - name: 💬 Set Docker Hub Description + # uses: peter-evans/dockerhub-description@v2 + # with: + # repository: lissy93/dashy + # readme-filepath: ./README.md + # short-description: Dashy - A self-hosted start page for your server + # username: ${{ secrets.DOCKER_USERNAME }} + # password: ${{ secrets.DOCKER_PASSWORD }}