From db51be62bb1df03272d4629bf59efae0d46fedec Mon Sep 17 00:00:00 2001 From: ubergeek77 Date: Sun, 17 Dec 2023 21:20:19 -0600 Subject: [PATCH] Test a build without alpine edge --- .github/workflows/build-multiarch.yml | 20 ++++----- Dockerfile-frontend | 64 +++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 Dockerfile-frontend diff --git a/.github/workflows/build-multiarch.yml b/.github/workflows/build-multiarch.yml index 395174c..9605cf5 100644 --- a/.github/workflows/build-multiarch.yml +++ b/.github/workflows/build-multiarch.yml @@ -122,7 +122,7 @@ jobs: file: ./${{ env.FE_REPO }}/Dockerfile platforms: ${{ matrix.docker-target }} push: true - tags: ${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.FE_REPO }}:${{ env.FE_TAG }}-${{ matrix.target-short }} + tags: testing-${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.FE_REPO }}:${{ env.FE_TAG }}-${{ matrix.target-short }} - name: Build and push Backend (${{ env.BE_TAG }}, ${{ matrix.docker-target }}) if: github.event.inputs.be-tag != '' uses: docker/build-push-action@v4 @@ -131,7 +131,7 @@ jobs: file: ./${{ env.BE_REPO }}/Dockerfile platforms: ${{ matrix.docker-target }} push: true - tags: ${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.BE_REPO }}:${{ env.BE_TAG }}-${{ matrix.target-short }} + tags: testing-${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.BE_REPO }}:${{ env.BE_TAG }}-${{ matrix.target-short }} stop-runners: needs: [launch-runners,build-images] @@ -175,16 +175,16 @@ jobs: uses: ubergeek77/squash-docker-tags@v1 with: source-tags: | - ${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.FE_REPO }}:${{ env.FE_TAG }}-amd64 - ${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.FE_REPO }}:${{ env.FE_TAG }}-arm - ${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.FE_REPO }}:${{ env.FE_TAG }}-arm64 - destination-tag: ${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.FE_REPO }}:${{ env.FE_TAG }} + testing-${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.FE_REPO }}:${{ env.FE_TAG }}-amd64 + testing-${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.FE_REPO }}:${{ env.FE_TAG }}-arm + testing-${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.FE_REPO }}:${{ env.FE_TAG }}-arm64 + destination-tag: testing-${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.FE_REPO }}:${{ env.FE_TAG }} - name: Squash Backend Multiarch Tags if: github.event.inputs.be-tag != '' uses: ubergeek77/squash-docker-tags@v1 with: source-tags: | - ${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.BE_REPO }}:${{ env.BE_TAG }}-amd64 - ${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.BE_REPO }}:${{ env.BE_TAG }}-arm - ${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.BE_REPO }}:${{ env.BE_TAG }}-arm64 - destination-tag: ${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.BE_REPO }}:${{ env.BE_TAG }} + testing-${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.BE_REPO }}:${{ env.BE_TAG }}-amd64 + testing-${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.BE_REPO }}:${{ env.BE_TAG }}-arm + testing-${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.BE_REPO }}:${{ env.BE_TAG }}-arm64 + destination-tag: testing-${{ env.DST_REGISTRY }}/${{ github.repository_owner }}/${{ env.BE_REPO }}:${{ env.BE_TAG }} diff --git a/Dockerfile-frontend b/Dockerfile-frontend new file mode 100644 index 0000000..48a93fb --- /dev/null +++ b/Dockerfile-frontend @@ -0,0 +1,64 @@ +FROM node:20-alpine as builder + +# Added vips-dev and pkgconfig so that local vips is used instead of prebuilt +# Done for two reasons: +# - libvips binaries are not available for ARM32 +# - It can break depending on the CPU (https://github.com/LemmyNet/lemmy-ui/issues/1566) +RUN apk update && apk upgrade && apk add --no-cache curl yarn python3 build-base gcc wget git vips-dev pkgconfig + +# Install node-gyp +RUN npm install -g node-gyp + +WORKDIR /usr/src/app + +ENV npm_config_target_platform=linux +ENV npm_config_target_libc=musl + +# Cache deps +COPY package.json yarn.lock ./ + +RUN yarn --production --prefer-offline --pure-lockfile --network-timeout 100000 + +# Build +COPY generate_translations.js \ + tsconfig.json \ + webpack.config.js \ + .babelrc \ + ./ + +COPY lemmy-translations lemmy-translations +COPY src src +COPY .git .git + +# Set UI version +RUN echo "export const VERSION = '$(git describe --tag)';" > "src/shared/version.ts" + +RUN yarn --production --prefer-offline --network-timeout 100000 +RUN NODE_OPTIONS="--max-old-space-size=8192" yarn build:prod + +RUN rm -rf ./node_modules/import-sort-parser-typescript +RUN rm -rf ./node_modules/typescript +RUN rm -rf ./node_modules/npm + +RUN du -sh ./node_modules/* | sort -nr | grep '\dM.*' + +FROM node:20-alpine as runner +ENV NODE_ENV=production + +# Upgrade to edge to fix sharp/libvips issues +RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories +RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories + +RUN apk update && apk upgrade && apk add curl vips-cpp + +COPY --from=builder /usr/src/app/dist /app/dist +COPY --from=builder /usr/src/app/node_modules /app/node_modules + +RUN chown -R node:node /app + +HEALTHCHECK --interval=60s --start-period=10s --retries=2 --timeout=10s CMD curl -ILfSs http://localhost:1234/ > /dev/null || exit 1 + +USER node +EXPOSE 1234 +WORKDIR /app +CMD exec node dist/js/server.js