Skip to content

Instantly share code, notes, and snippets.

@esamattis
Last active December 21, 2023 20:21
Show Gist options
  • Save esamattis/bb82b149813aa8725d0e81892143b0d5 to your computer and use it in GitHub Desktop.
Save esamattis/bb82b149813aa8725d0e81892143b0d5 to your computer and use it in GitHub Desktop.
How to deploy a single app to a container from a pnpm monorepo using `pnpm deploy` in Github Actions
name: Deploy myapp as a container
jobs:
deploy-myapp:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 16
- uses: pnpm/action-setup@v2.0.1
with:
version: 7.9.5
- name: Set pnpm store path
run: echo "PNPM_STORE_PATH=$(pnpm store path)" >> $GITHUB_ENV
- name: Cache pnpm modules
uses: actions/cache@v2
with:
path: ${{ env.PNPM_STORE_PATH }}
key: pnpm-${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
pnpm-${{ runner.os }}-
- name: Cache turborepo
uses: actions/cache@v2
with:
path: node_modules/.cache/turbo/
key: turbo-${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
turbo-${{ runner.os }}-
- name: Install node modules only for the root package and myapp
run: pnpm install --filter root --filter myapp
# Turborepo is installed to the workspace root which is why
# we need to install root deps as well
- name: Build myapp only with Turborepo
run: ./node_modules/.bin/turbo run build --filter myapp
- name: Run pnpm deploy
run: pnpm deploy --filter myapp pnpm-deploy-output
- name: Authenticate to the Container Registry
run: XXX
- name: Build the container and push it to Container Registry
uses: docker/build-push-action@v2
with:
context: .
file: packages/myapp/Dockerfile
push: true
tags: XXX
- name: Deploy the container
run: XXX
FROM node:14-slim
ENV NODE_ENV=production
COPY pnpm-deploy-output /app
WORKDIR /app
ENTRYPOINT ["/app/entrypoint.sh"]
@esamattis
Copy link
Author

@rohanrajpal looking at our last Github Actions run it installed 2301 node modules in 15 seconds. Got full cache hit (no downloaded modules). In comparison the same installation takes on my Intel i9 8-core MacBook Pro (2020) 23 seconds with the full cache hit.

@rohanrajpal
Copy link

@rohanrajpal looking at our last Github Actions run it installed 2301 node modules in 15 seconds. Got full cache hit (no downloaded modules). In comparison the same installation takes on my Intel i9 8-core MacBook Pro (2020) 23 seconds with the full cache hit.

Pretty fast! Guess it shall work then, thanks!

@Clee681
Copy link

Clee681 commented Feb 5, 2023

@esamattis thanks for sharing this!

Wondering if you could share parts of your /app/entrypoint.sh file, since I'm getting "module not found" errors when trying to run the container.

@esamattis
Copy link
Author

esamattis commented Feb 6, 2023

@Clee681 It's just

#!/bin/sh

set -eu

exec node myapp.js

But the node_modules/.bin usage might be broken inside the container because the file system paths are different on GH Actions and the container. So invoke your app directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment