From 42adb7b5631928aa6cb8c465c4e1c19345e78780 Mon Sep 17 00:00:00 2001 From: SebClem Date: Tue, 13 Aug 2024 13:23:32 +0200 Subject: [PATCH] Addapt docker file --- .github/workflows/build_addon.yml | 37 ++++++++++++++- deploy | 5 --- nextcloud_backup/Dockerfile | 45 +++++++++++++------ nextcloud_backup/backend.code-workspace | 11 ----- nextcloud_backup/backend/src/postInit.ts | 2 +- .../rootfs/usr/bin/nextcloud_backup.sh | 2 +- 6 files changed, 70 insertions(+), 32 deletions(-) delete mode 100755 deploy delete mode 100644 nextcloud_backup/backend.code-workspace diff --git a/.github/workflows/build_addon.yml b/.github/workflows/build_addon.yml index 27703ec..533fe04 100644 --- a/.github/workflows/build_addon.yml +++ b/.github/workflows/build_addon.yml @@ -13,7 +13,7 @@ env: IMAGE_SOURCE: https://github.com/Sebclem/hassio-nextcloud-backup jobs: - build-font: + build-front: name: Build Front runs-on: ubuntu-latest steps: @@ -44,6 +44,41 @@ jobs: name: front_dist path: nextcloud_backup/frontend/dist/ + build-back: + name: Build Front + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Enable corepack + run: corepack enable + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: "pnpm" + cache-dependency-path: nextcloud_backup/backend/pnpm-lock.yaml + + - name: Install dependencies + run: pnpm i + working-directory: nextcloud_backup/backend + + - name: Lint + run: pnpm lint + working-directory: nextcloud_backup/backend + + - name: Build + run: pnpm build + working-directory: nextcloud_backup/backend + + - name: Upload production-ready build files + uses: actions/upload-artifact@v4 + with: + name: front_dist + path: nextcloud_backup/backend/dist/ + # build-dockers: # runs-on: ubuntu-latest # strategy: diff --git a/deploy b/deploy deleted file mode 100755 index 14a0bf8..0000000 --- a/deploy +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -docker run --rm --privileged multiarch/qemu-user-static --reset -p yes && \ -docker run --rm --privileged -v ~/.docker:/root/.docker -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd)/nextcloud_backup:/data homeassistant/amd64-builder --all -t /data - diff --git a/nextcloud_backup/Dockerfile b/nextcloud_backup/Dockerfile index 9626ca8..776c0c8 100644 --- a/nextcloud_backup/Dockerfile +++ b/nextcloud_backup/Dockerfile @@ -1,5 +1,28 @@ -ARG BUILD_FROM=ghcr.io/hassio-addons/base/amd64:12.2.2 -FROM ${BUILD_FROM} +FROM node:20 AS frontend-builder + +WORKDIR /app + +COPY frontend/package.json frontend/pnpm-lock.yaml ./ +RUN corepack enable +RUN pnpm install + +COPY frontend/ . + +RUN pnpm build + +FROM node:20 AS backend-builder + +WORKDIR /app + +COPY backend/package.json backend/pnpm-lock.yaml ./ +RUN corepack enable +RUN pnpm install + +COPY backend/ . + +RUN pnpm build + +FROM ghcr.io/hassio-addons/base/amd64:16.2.1 # Copy root filesystem COPY rootfs/etc /etc/ @@ -12,21 +35,17 @@ RUN apk add --no-cache nodejs-current RUN mkdir -p /usr/local/sbin/ RUN ln -s /usr/bin/node /usr/local/sbin/node -# Copy only package*.json -COPY rootfs/opt/nextcloud_backup/package*.json /opt/nextcloud_backup/ -COPY rootfs/opt/nextcloud_backup/.yarnrc.yml /opt/nextcloud_backup/ -COPY rootfs/opt/nextcloud_backup/.yarn/releases/* /opt/nextcloud_backup/.yarn/releases/ WORKDIR /opt/nextcloud_backup/ -# Enable Yarn +COPY backend/package.json backend/pnpm-lock.yaml ./ RUN corepack enable - -# Install packages -RUN yarn install +RUN pnpm install # Copy all source code -COPY rootfs/opt/ /opt/ + +COPY --from=backend-builder /app/dist . +COPY --from=frontend-builder /app/dist ./public # Build arguments ARG BUILD_ARCH @@ -48,8 +67,8 @@ LABEL \ org.label-schema.name="Nextcloud Backup" \ org.label-schema.schema-version="1.0" \ org.label-schema.url="https://addons.community" \ - org.label-schema.usage="https://github.com/hassio-addons/addon-example/tree/master/README.md" \ + org.label-schema.usage="https://github.com/Sebclem/hassio-nextcloud-backup/tree/master/README.md" \ org.label-schema.vcs-ref=${BUILD_REF} \ - org.label-schema.vcs-url="https://github.com/hassio-addons/addon-example" \ + org.label-schema.vcs-url="https://github.com/Sebclem/hassio-nextcloud-backup" \ org.label-schema.vendor="Sebclem"\ org.opencontainers.image.source=${IMAGE_SOURCE} diff --git a/nextcloud_backup/backend.code-workspace b/nextcloud_backup/backend.code-workspace deleted file mode 100644 index 0cb4068..0000000 --- a/nextcloud_backup/backend.code-workspace +++ /dev/null @@ -1,11 +0,0 @@ -{ - "folders": [ - { - "path": "backend" - }, - { - "path": "frontend" - } - ], - "settings": {} -} \ No newline at end of file diff --git a/nextcloud_backup/backend/src/postInit.ts b/nextcloud_backup/backend/src/postInit.ts index 4ea3083..8208ae4 100644 --- a/nextcloud_backup/backend/src/postInit.ts +++ b/nextcloud_backup/backend/src/postInit.ts @@ -77,7 +77,7 @@ function postInit() { () => { logger.info("Cron: " + kleur.green().bold("Go !")); }, - (reason) => { + () => { logger.info("Cron: " + kleur.red().bold("FAIL !")); } ); diff --git a/nextcloud_backup/rootfs/usr/bin/nextcloud_backup.sh b/nextcloud_backup/rootfs/usr/bin/nextcloud_backup.sh index 060862d..49a2968 100755 --- a/nextcloud_backup/rootfs/usr/bin/nextcloud_backup.sh +++ b/nextcloud_backup/rootfs/usr/bin/nextcloud_backup.sh @@ -21,4 +21,4 @@ else CREATE_BACKUP_TIMEOUT='info' fi -LOG_LEVEL=$LOG_LEVEL CREATE_BACKUP_TIMEOUT=$CREATE_BACKUP_TIMEOUT yarn start \ No newline at end of file +LOG_LEVEL=$LOG_LEVEL CREATE_BACKUP_TIMEOUT=$CREATE_BACKUP_TIMEOUT node server.js \ No newline at end of file