diff --git a/.github/workflows/webapp.yml b/.github/workflows/webapp.yml new file mode 100644 index 000000000..51b5fdeeb --- /dev/null +++ b/.github/workflows/webapp.yml @@ -0,0 +1,59 @@ +name: 🚀 Build Webapp Docker +on: + push: + paths: + - "apps/webapp/**" + branches: + - dev + - main + pull_request: {} + workflow_dispatch: {} +permissions: + actions: write + contents: read + +jobs: + build: + name: 🐳 Build + # only build/deploy main branch on pushes + if: ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev') && github.event_name == 'push' }} + runs-on: ubuntu-latest + steps: + - name: 🛑 Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.9.1 + + - name: ⬇️ Checkout repo + uses: actions/checkout@v3 + + - name: 🐳 Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + # Setup cache + - name: ⚡️ Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: 🐳 Docker build + uses: docker/build-push-action@v3 + with: + context: . + file: apps/webapp/Dockerfile + push: false + build-args: | + COMMIT_SHA=${{ github.sha }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new + + # This ugly bit is necessary if you don't want your cache to grow forever + # till it hits GitHub's limit of 5GB. + # Temp fix + # https://github.com/docker/build-push-action/issues/252 + # https://github.com/moby/buildkit/issues/1896 + - name: 🚚 Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/apps/webapp/Dockerfile b/apps/webapp/Dockerfile index f276e62a1..a8b44017c 100644 --- a/apps/webapp/Dockerfile +++ b/apps/webapp/Dockerfile @@ -1,26 +1,23 @@ FROM node:lts-bullseye-slim AS pruner -RUN apt-get update && apt-get install openssl python3 -y +RUN apt-get update && apt-get install openssl -y WORKDIR /app -RUN yarn global add turbo +RUN npm install turbo -g COPY . . RUN turbo prune --scope=webapp --docker RUN find . -name "node_modules" -type d -prune -exec rm -rf '{}' + # Base strategy to have layer caching FROM node:lts-bullseye-slim AS base -RUN apt-get update && apt-get install openssl curl build-essential cmake python3 -y +RUN apt-get update && apt-get install openssl g++ make wget python3 -y +ENV PULSAR_CPP_CLIENT_VERSION=2.10.3 +RUN wget https://archive.apache.org/dist/pulsar/pulsar-${PULSAR_CPP_CLIENT_VERSION}/DEB/apache-pulsar-client.deb +RUN wget https://archive.apache.org/dist/pulsar/pulsar-${PULSAR_CPP_CLIENT_VERSION}/DEB/apache-pulsar-client-dev.deb +RUN dpkg -i --force-architecture ./apache-pulsar-client*.deb WORKDIR /app COPY .gitignore .gitignore COPY --from=pruner /app/out/json/ . COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml COPY --from=pruner /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml -# install pulsar stuff -ENV PULSAR_VERSION=2.10.3 -RUN cd "$(mktemp -d)" && \ - curl -SLO 'http://archive.apache.org/dist/pulsar/pulsar-'$PULSAR_VERSION'/DEB/apache-pulsar-client.deb' && \ - curl -SLO 'http://archive.apache.org/dist/pulsar/pulsar-'$PULSAR_VERSION'/DEB/apache-pulsar-client-dev.deb' && \ - apt install ./apache-pulsar-client*.deb -# COPY --from=pruner /app/out/full/ . FROM base AS dev-deps WORKDIR /app @@ -37,36 +34,36 @@ RUN pnpm install --prod --frozen-lockfile COPY --from=pruner /app/out/full/apps/webapp/prisma/schema.prisma /app/apps/webapp/prisma/schema.prisma RUN pnpx prisma generate --schema /app/apps/webapp/prisma/schema.prisma -FROM base AS builder -WORKDIR /app -RUN corepack enable -ENV NODE_ENV production -COPY --from=pruner /app/out/full/ . -COPY --from=dev-deps /app/ . -COPY turbo.json turbo.json -RUN pnpm run generate -RUN pnpm run build --filter=webapp... +# FROM base AS builder +# WORKDIR /app +# RUN corepack enable +# ENV NODE_ENV production +# COPY --from=pruner /app/out/full/ . +# COPY --from=dev-deps /app/ . +# COPY turbo.json turbo.json +# RUN pnpm run generate +# RUN pnpm run build --filter=webapp... -# Runner -FROM node:lts-bullseye-slim AS runner -RUN apt-get update && apt-get install -y openssl -WORKDIR /app -RUN corepack enable -ENV NODE_ENV production -RUN addgroup --system --gid 1001 nodejs -RUN adduser --system --uid 1001 remixjs -RUN chown -R remixjs:nodejs /app -USER remixjs +# # Runner +# FROM node:lts-bullseye-slim AS runner +# RUN apt-get update && apt-get install -y openssl +# WORKDIR /app +# RUN corepack enable +# ENV NODE_ENV production +# RUN addgroup --system --gid 1001 nodejs +# RUN adduser --system --uid 1001 remixjs +# RUN chown -R remixjs:nodejs /app +# USER remixjs -COPY --from=pruner --chown=remixjs:nodejs /app/out/full/ . -COPY --from=production-deps --chown=remixjs:nodejs /app . -COPY --from=builder --chown=remixjs:nodejs /app/apps/webapp/app/styles/tailwind.css ./apps/webapp/app/styles/tailwind.css -COPY --from=builder --chown=remixjs:nodejs /app/apps/webapp/build/server.js ./apps/webapp/build/server.js -COPY --from=builder --chown=remixjs:nodejs /app/apps/webapp/build ./apps/webapp/build -COPY --from=builder --chown=remixjs:nodejs /app/apps/webapp/public ./apps/webapp/public -COPY --from=builder --chown=remixjs:nodejs /app/apps/webapp/prisma/schema.prisma ./apps/webapp/build/schema.prisma -COPY --from=builder --chown=remixjs:nodejs /app/apps/webapp/prisma/migrations ./apps/webapp/build/migrations -COPY --from=builder --chown=remixjs:nodejs /app/apps/webapp/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node ./apps/webapp/build/libquery_engine-debian-openssl-1.1.x.so.node +# COPY --from=pruner --chown=remixjs:nodejs /app/out/full/ . +# COPY --from=production-deps --chown=remixjs:nodejs /app . +# COPY --from=builder --chown=remixjs:nodejs /app/apps/webapp/app/styles/tailwind.css ./apps/webapp/app/styles/tailwind.css +# COPY --from=builder --chown=remixjs:nodejs /app/apps/webapp/build/server.js ./apps/webapp/build/server.js +# COPY --from=builder --chown=remixjs:nodejs /app/apps/webapp/build ./apps/webapp/build +# COPY --from=builder --chown=remixjs:nodejs /app/apps/webapp/public ./apps/webapp/public +# COPY --from=builder --chown=remixjs:nodejs /app/apps/webapp/prisma/schema.prisma ./apps/webapp/build/schema.prisma +# COPY --from=builder --chown=remixjs:nodejs /app/apps/webapp/prisma/migrations ./apps/webapp/build/migrations +# COPY --from=builder --chown=remixjs:nodejs /app/apps/webapp/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node ./apps/webapp/build/libquery_engine-debian-openssl-1.1.x.so.node -# release_command = "pnpx prisma migrate deploy --schema apps/webapp/prisma/schema.prisma" -ENTRYPOINT ["pnpm", "--filter", "webapp", "run", "start"] \ No newline at end of file +# # release_command = "pnpx prisma migrate deploy --schema apps/webapp/prisma/schema.prisma" +# ENTRYPOINT ["pnpm", "--filter", "webapp", "run", "start"] \ No newline at end of file diff --git a/flightcontrol.json b/flightcontrol.json index 393a88720..59c84c136 100644 --- a/flightcontrol.json +++ b/flightcontrol.json @@ -48,6 +48,9 @@ "apps/webapp/types/**", "apps/webapp/nixpacks.toml" ], + "dependsOn": [ + "p-db" + ], "envVariables": { "NIXPACKS_CONFIG_FILE": "./apps/webapp/nixpacks.toml", "FROM_EMAIL": "hello@email.trigger.dev", @@ -125,7 +128,10 @@ "value": "origin" } } - } + }, + "dependsOn": [ + "p-webapp" + ] }, { "id": "p-db",