-
-
Save esamattis/bb82b149813aa8725d0e81892143b0d5 to your computer and use it in GitHub Desktop.
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/[email protected] | |
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"] |
@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 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!
@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.
@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.
Got it, and how are the build times like? Is Github Actions poweful enough to build decent sized projects (nestjs project with ~1200 nodemodules) in a minute?
I know only way to know is to give it a shot, but just curious to know what your build times are right now.