diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d11f459..08f4593 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,7 +34,11 @@ jobs: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} REPOSITORY: ${{ vars.REPOSITORY }} IMAGE_TAG: ${{ github.sha }} - DATABASE_URL: 'file:./dev.db' + DATABASE_URL: "file:./dev.db" + CLUSTER_NAME: ${{ secrets.CLUSTER_NAME }} + SERVICE_NAME: ${{ vars.REPOSITORY }}-prod-service run: | docker build --output type=image,push=true --platform linux/arm64 -t $ECR_REGISTRY/$REPOSITORY:$IMAGE_TAG . 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 container will update now" diff --git a/.github/workflows/stage.yml b/.github/workflows/stage.yml index f2fc714..72a7398 100644 --- a/.github/workflows/stage.yml +++ b/.github/workflows/stage.yml @@ -34,7 +34,11 @@ jobs: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} REPOSITORY: ${{ vars.REPOSITORY }} IMAGE_TAG: ${{ github.sha }} - DATABASE_URL: 'file:./dev.db' + DATABASE_URL: "file:./dev.db" + CLUSTER_NAME: ${{ secrets.CLUSTER_NAME }} + SERVICE_NAME: ${{ vars.REPOSITORY }}-stage-service run: | docker build --output type=image,push=true --platform linux/arm64 -t $ECR_REGISTRY/$REPOSITORY:$IMAGE_TAG . 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 container will update now" diff --git a/dockerfile b/dockerfile index 878295f..87f1728 100644 --- a/dockerfile +++ b/dockerfile @@ -1,17 +1,17 @@ # Build container -FROM node:22-alpine AS builder +FROM node:current-alpine AS builder COPY . ./ ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" -RUN corepack enable +RUN npm i -g pnpm RUN pnpm i --frozen-lockfile RUN pnpm prisma generate RUN pnpm run build # Deployment container -FROM node:22-alpine AS deployment +FROM node:current-alpine AS deployment # Copy stuff from build container to ensure we have prisma and everything it needs COPY --from=builder /.output / @@ -27,4 +27,4 @@ COPY ./entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh EXPOSE 3000 ENTRYPOINT ["/entrypoint.sh"] -CMD ["node", "./server/index.mjs"] \ No newline at end of file +CMD ["node", "./server/index.mjs"] diff --git a/entrypoint.sh b/entrypoint.sh index c08aa88..e22eb69 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,6 +3,7 @@ # Apply migrations and initialize migrations if it does not exist pnpm prisma generate pnpm prisma migrate deploy +pnpm prisma db seed # Run the CMD command from the dockerfile exec "$@" diff --git a/prisma/seed.ts b/prisma/seed.ts index 578dd88..5c1d02d 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -1,13 +1,22 @@ -import { prisma } from '../server/utils/prisma' +import { Param } from '@prisma/client/runtime/client' +import { PrismaClient } from "./generated/client" +import { PrismaBetterSqlite3 } from "@prisma/adapter-better-sqlite3"; +import "dotenv/config"; +const connectionString = `${process.env.DATABASE_URL}`; + +const adapter = new PrismaBetterSqlite3({ url: connectionString }); +const prisma = new PrismaClient({ adapter }); async function main() { console.log('Start seeding...') // Create a User - const user1 = await prisma.user.create({ - data: { - name: "Sample Name", // modify this fit your needs - email: "email@example.com" + const user1 = await prisma.user.upsert({ + where: {email: 'seeded-user@email.com'}, + update: {}, + create: { + email: 'seeded-user@email.com', + name: 'Sample Seeded User' } })