forked from kokonect-link/cherrypick
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d53139
commit d61dc7b
Showing
7 changed files
with
218 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
name: Publish Docker image (deploy) | ||
|
||
on: | ||
push: | ||
branches: | ||
- develop | ||
workflow_dispatch: | ||
|
||
jobs: | ||
push_to_registry: | ||
name: Push Docker image to Container Registry | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Free Disk Space | ||
uses: jlumbroso/free-disk-space@main | ||
with: | ||
# This might remove tools that are actually needed, if set to "true" but frees about 6 GB | ||
tool-cache: false | ||
# All of these default to true, but feel free to set to "false" if necessary for your workflow | ||
android: true | ||
dotnet: true | ||
haskell: true | ||
large-packages: true | ||
swap-storage: true | ||
- name: Check out the repo | ||
uses: actions/[email protected] | ||
- name: Set environment variables | ||
run: | | ||
echo "COMMIT_SHA=$(git rev-parse --short=7 HEAD)" >> $GITHUB_ENV | ||
echo "CLIENT_ASSETS_BASE_URL=${{ secrets.CLIENT_ASSETS_BASE_URL }}" >> $GITHUB_ENV | ||
echo "CLIENT_ASSETS_DIR=$(git show --no-patch --format='%at' HEAD)-$(git rev-parse --short=7 HEAD)" >> $GITHUB_ENV | ||
- name: Add SSH key | ||
env: | ||
SSH_AUTH_SOCK: /tmp/ssh_agent.sock | ||
run: | | ||
mkdir -p ~/.ssh | ||
ssh-keyscan -p ${{ secrets.ARM_NODE_PORT }} -H ${{ secrets.ARM_NODE_ADDR }} >> ~/.ssh/known_hosts | ||
ssh-agent -a $SSH_AUTH_SOCK > /dev/null | ||
echo "${{ secrets.SSH_PRIVATE_KEY }}" | ssh-add - | ||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/[email protected] | ||
env: | ||
SSH_AUTH_SOCK: /tmp/ssh_agent.sock | ||
with: | ||
endpoint: unix:///var/run/docker.sock | ||
platforms: linux/amd64 | ||
append: | | ||
- endpoint: ssh://${{ secrets.ARM_NODE_USER }}@${{ secrets.ARM_NODE_ADDR }}:${{ secrets.ARM_NODE_PORT }} | ||
platforms: linux/arm64 | ||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ghcr.io/${{ github.repository }}:${{ env.COMMIT_SHA }}, ghcr.io/${{ github.repository }}:develop | ||
- name: Log in to Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: pnpm/action-setup@v2 | ||
- name: Install frontend dependencies | ||
run: | | ||
git submodule update --init | ||
NODE_ENV=production pnpm --filter cherrypick-js install | ||
NODE_ENV=production pnpm --filter frontend install | ||
- name: Build frontend | ||
run: | | ||
sed -i "s/outDir: __dirname + '\/..\/..\/built\/_vite_'/outDir: __dirname + '\/..\/..\/vite'/" packages/frontend/vite.config.ts | ||
NODE_ENV=production pnpm --filter cherrypick-js build | ||
NODE_ENV=production pnpm --filter frontend build | ||
sed -i "s/outDir: __dirname + '\/..\/..\/vite'/outDir: __dirname + '\/..\/..\/built\/_vite_'/" packages/frontend/vite.config.ts | ||
- name: Deploy frontend | ||
run: echo "${{ secrets.UPLOAD_SCRIPT }}" | base64 -d | node | ||
- name: Build and Push to Container registry | ||
uses: docker/build-push-action@v5 | ||
env: | ||
SSH_AUTH_SOCK: /tmp/ssh_agent.sock | ||
with: | ||
builder: ${{ steps.buildx.outputs.name }} | ||
context: . | ||
file: deploy.Dockerfile | ||
push: true | ||
platforms: ${{ steps.buildx.outputs.platforms }} | ||
provenance: false | ||
tags: ghcr.io/${{ github.repository }}:${{ env.COMMIT_SHA }}, ghcr.io/${{ github.repository }}:develop | ||
labels: ${{ env.COMMIT_SHA }}, develop | ||
build-args: | | ||
CLIENT_ASSETS_BASE_URL=${{ env.CLIENT_ASSETS_BASE_URL }} | ||
CLIENT_ASSETS_DIR=${{ env.CLIENT_ASSETS_DIR }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# syntax = docker/dockerfile:1.4 | ||
|
||
ARG NODE_VERSION=20.5.1-bullseye | ||
ARG CLIENT_ASSETS_BASE_URL | ||
ARG CLIENT_ASSETS_DIR | ||
|
||
# build assets & compile TypeScript | ||
|
||
FROM --platform=$BUILDPLATFORM node:${NODE_VERSION} AS native-builder | ||
|
||
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ | ||
--mount=type=cache,target=/var/lib/apt,sharing=locked \ | ||
rm -f /etc/apt/apt.conf.d/docker-clean \ | ||
; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache \ | ||
&& apt-get update \ | ||
&& apt-get install -yqq --no-install-recommends \ | ||
build-essential | ||
|
||
RUN corepack enable | ||
|
||
WORKDIR /cherrypick | ||
|
||
COPY --link ["pnpm-lock.yaml", "pnpm-workspace.yaml", "package.json", "./"] | ||
COPY --link ["scripts", "./scripts"] | ||
COPY --link ["packages/backend/package.json", "./packages/backend/"] | ||
COPY --link ["packages/frontend/package.json", "./packages/frontend/"] | ||
COPY --link ["packages/sw/package.json", "./packages/sw/"] | ||
COPY --link ["packages/cherrypick-js/package.json", "./packages/cherrypick-js/"] | ||
|
||
ARG NODE_ENV=production | ||
|
||
RUN --mount=type=cache,target=/root/.local/share/pnpm/store,sharing=locked \ | ||
pnpm i --frozen-lockfile --aggregate-output --force | ||
|
||
COPY --link . ./ | ||
|
||
RUN git submodule update --init | ||
RUN sed -i '/packages\/frontend/ s/^/# /' pnpm-workspace.yaml | ||
RUN pnpm build | ||
RUN sed -i '/packages\/frontend/ s/^# //' pnpm-workspace.yaml | ||
RUN rm -rf .git/ | ||
|
||
# build native dependencies for target platform | ||
|
||
FROM --platform=$TARGETPLATFORM node:${NODE_VERSION} AS target-builder | ||
|
||
RUN apt-get update \ | ||
&& apt-get install -yqq --no-install-recommends \ | ||
build-essential | ||
|
||
RUN corepack enable | ||
|
||
WORKDIR /cherrypick | ||
|
||
COPY --link ["pnpm-lock.yaml", "pnpm-workspace.yaml", "package.json", "./"] | ||
COPY --link ["scripts", "./scripts"] | ||
COPY --link ["packages/backend/package.json", "./packages/backend/"] | ||
|
||
ARG NODE_ENV=production | ||
|
||
RUN --mount=type=cache,target=/root/.local/share/pnpm/store,sharing=locked \ | ||
pnpm i --frozen-lockfile --aggregate-output | ||
|
||
FROM --platform=$TARGETPLATFORM node:${NODE_VERSION}-slim AS runner | ||
|
||
ARG UID="991" | ||
ARG GID="991" | ||
|
||
RUN apt-get update \ | ||
&& apt-get install -y --no-install-recommends \ | ||
ffmpeg tini curl libjemalloc-dev libjemalloc2 \ | ||
&& ln -s /usr/lib/$(uname -m)-linux-gnu/libjemalloc.so.2 /usr/local/lib/libjemalloc.so \ | ||
&& corepack enable \ | ||
&& groupadd -g "${GID}" cherrypick \ | ||
&& useradd -l -u "${UID}" -g "${GID}" -m -d /cherrypick cherrypick \ | ||
&& find / -type d -path /proc -prune -o -type f -perm /u+s -ignore_readdir_race -exec chmod u-s {} \; \ | ||
&& find / -type d -path /proc -prune -o -type f -perm /g+s -ignore_readdir_race -exec chmod g-s {} \; \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists | ||
|
||
USER cherrypick | ||
WORKDIR /cherrypick | ||
|
||
COPY --chown=cherrypick:cherrypick --from=target-builder /cherrypick/node_modules ./node_modules | ||
COPY --chown=cherrypick:cherrypick --from=target-builder /cherrypick/packages/backend/node_modules ./packages/backend/node_modules | ||
COPY --chown=cherrypick:cherrypick --from=native-builder /cherrypick/built ./built | ||
COPY --chown=cherrypick:cherrypick --from=native-builder /cherrypick/packages/backend/built ./packages/backend/built | ||
COPY --chown=cherrypick:cherrypick --from=native-builder /cherrypick/fluent-emojis /cherrypick/fluent-emojis | ||
COPY --chown=cherrypick:cherrypick . ./ | ||
|
||
RUN mv ./vite ./built/_vite_ | ||
|
||
ENV LD_PRELOAD=/usr/local/lib/libjemalloc.so | ||
ENV MALLOC_CONF=background_thread:true,metadata_thp:auto,dirty_decay_ms:30000,muzzy_decay_ms:30000 | ||
ENV NODE_ENV=production | ||
ENV CLIENT_ASSETS_BASE_URL=${CLIENT_ASSETS_BASE_URL} | ||
ENV CLIENT_ASSETS_DIR=${CLIENT_ASSETS_DIR} | ||
HEALTHCHECK --interval=5s --retries=20 CMD ["/bin/bash", "/cherrypick/healthcheck.sh"] | ||
ENTRYPOINT ["/usr/bin/tini", "--"] | ||
CMD ["pnpm", "run", "migrateandstart:docker"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters