Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.git/
.env
node_modules/
.nuxt/
.output/
README.md
dockerfile
.dockerignore
prisma/generated
27 changes: 13 additions & 14 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,30 @@ jobs:
build:
permissions:
id-token: write # This is required for requesting the JWT
runs-on: ubuntu-latest

runs-on: ubuntu-24.04-arm
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v1
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::654654236858:role/GithubActions
role-to-assume: ${{ secrets.ACTIONS_ROLE_ARN }}
role-session-name: GitHub_to_AWS_via_FederatedOIDC
aws-region: us-east-2

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build and Push Docker image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry}}
REPOSITORY: mttp-repo
IMAGE_TAG: ${{ github.sha}}
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ vars.REPOSITORY }}
IMAGE_TAG: ${{ github.sha }}
DATABASE_URL: 'file:./dev.db'
CLUSTER_NAME: ${{ secrets.CLUSTER_NAME }}
SERVICE_NAME: ${{ vars.REPOSITORY }}-prod-service
run: |
docker buildx build --output type=image,push=true --platform linux/arm64 -t $ECR_REGISTRY/$REPOSITORY:$IMAGE_TAG .
docker buildx build --output type=image,push=true --platform linux/arm64 -t $ECR_REGISTRY/$REPOSITORY:prod .
docker build --output type=image,push=true --platform linux/arm64 -t $ECR_REGISTRY/$REPOSITORY:prod .
aws ecs update-service --cluster $CLUSTER_NAME --service $SERVICE_NAME --force-new-deployment --output text --query "service.serviceName" >/dev/null
echo "The ECS service will update now"
27 changes: 13 additions & 14 deletions .github/workflows/stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,30 @@ jobs:
build:
permissions:
id-token: write # This is required for requesting the JWT
runs-on: ubuntu-latest

runs-on: ubuntu-24.04-arm
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v1
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::654654236858:role/GithubActions
role-to-assume: ${{ secrets.ACTIONS_ROLE_ARN }}
role-session-name: GitHub_to_AWS_via_FederatedOIDC
aws-region: us-east-2

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build and Push Docker image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry}}
REPOSITORY: mttp-repo
IMAGE_TAG: ${{ github.sha}}-stage
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ vars.REPOSITORY }}
IMAGE_TAG: ${{ github.sha }}
DATABASE_URL: 'file:./dev.db'
CLUSTER_NAME: ${{ secrets.CLUSTER_NAME }}
SERVICE_NAME: ${{ vars.REPOSITORY }}-stage-service
run: |
docker buildx build --output type=image,push=true --platform linux/arm64 -t $ECR_REGISTRY/$REPOSITORY:$IMAGE_TAG .
docker buildx build --output type=image,push=true --platform linux/arm64 -t $ECR_REGISTRY/$REPOSITORY:stage .
docker build --output type=image,push=true --platform linux/arm64 -t $ECR_REGISTRY/$REPOSITORY:stage .
aws ecs update-service --cluster $CLUSTER_NAME --service $SERVICE_NAME --force-new-deployment --output text --query "service.serviceName" >/dev/null
echo "The ECS service will update now"
48 changes: 38 additions & 10 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,46 @@
FROM node:22-alpine AS builder
COPY . ./
# Build container
FROM node:lts-alpine AS builder

# Use Workdir because things like tailwind will scan the entire current dir and can cause issues if it scans root
WORKDIR /app

ENV PNPM_HOME="/pnpm"
COPY package.json ./
COPY pnpm-lock.yaml ./
COPY pnpm-workspace.yaml ./

ENV PNPM_HOME="~/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
RUN npm i -g pnpm

RUN pnpm i --frozen-lockfile

RUN pnpm i --force
RUN npx prisma generate
RUN ls /prisma/client
COPY . ./
RUN pnpm prisma generate
RUN pnpm run build

FROM node:22-alpine AS deployment

COPY --from=builder /.output /
COPY --from=builder /prisma/client /prisma/client
# Deployment container
FROM node:lts-alpine AS deployment
WORKDIR /app
# Copy stuff from build container to ensure we have prisma and everything it needs
COPY --from=builder /app/.output ./
COPY --from=builder /app/package.json ./
COPY --from=builder /app/pnpm-lock.yaml ./
COPY --from=builder /app/pnpm-workspace.yaml ./
COPY --from=builder /app/prisma ./prisma
# Commented out because MTTP is a Prisma 6 app
# COPY --from=builder /app/prisma.config.ts ./
RUN npm i -g pnpm

# Install Prisma without running any scripts to avoid running nuxt scripts
RUN pnpm i --dev --ignore-scripts --frozen-lockfile
# Run the build scripts needed for prisma to work (for migrations and seeding)
RUN pnpm rebuild esbuild better-sqlite3 @prisma/engines prisma
RUN pnpm prisma generate
COPY --from=builder /app/entrypoint.sh /entrypoint

# Ensure we can actually run the entrypoint script
RUN chmod +x /entrypoint
EXPOSE 3000
ENTRYPOINT ["/entrypoint"]
CMD ["node", "./server/index.mjs"]
10 changes: 10 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

# Apply migrations and initialize migrations if it does not exist
pnpm prisma generate
pnpm prisma migrate deploy
# Commenting out because we aren't seeding anything
# pnpm prisma db seed

# Run the CMD command from the dockerfile
exec "$@"
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
"postinstall": "nuxt prepare"
},
"devDependencies": {
"nuxt": "3.13.1"
"@prisma/client": "^6.6.0",
"prisma": "^6.6.0"
},
"description": "Look at the [Nuxt 3 documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"nuxt": "3.13.1",
"@nuxt/ui-templates": "^1.3.1",
"@nuxtjs/tailwindcss": "^6.8.0",
"@prisma/client": "^6.6.0",
"@types/node": "^20.8.7",
"autoprefixer": "^10.4.16",
"jose": "^6.0.10",
"nuxt-headlessui": "^1.1.4",
"papaparse": "^5.5.2",
"postcss": "^8.4.31",
"prisma": "^6.6.0",
"pug": "^3.0.2",
"tailwindcss": "^3.3.3",
"typescript": "^5.2.2",
Expand Down
Loading
Loading