Skip to content

Commit

Permalink
added Dockerfile at root directory
Browse files Browse the repository at this point in the history
  • Loading branch information
waseemrabani committed Feb 1, 2024
1 parent 22eb043 commit 6e8fdef
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .github/workflows/dev-formbricks-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ env:
ECR_REPOSITORY: dev-formbricks-ecr
ECS_CLUSTER: dev-lumi-cluster
ECS_SERVICE: dev-formbricks
SECRET_NAME: dev/formbricks/env
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
TIME_ZONE: Europe/London
Expand Down Expand Up @@ -42,6 +43,11 @@ jobs:
- name: Login to AWS ECR
id: login_ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Retrieve environment variables from Secrets Manager
run: |
aws secretsmanager get-secret-value --secret-id ${{env.SECRET_NAME}} --region ${{ env.AWS_REGION }} --query 'SecretString' --output json | jq -r '. | if type=="string" then fromjson else . end | to_entries | map("\(.key)=\(.value|tostring)") | .[]' > .env
env:
AWS_REGION: ${{ env.AWS_REGION }}
- name: Build, tag, and push image to AWS ECR
id: build_image
env:
Expand Down
57 changes: 57 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
FROM node:18-alpine AS installer
RUN corepack enable && corepack prepare pnpm@latest --activate

ARG DATABASE_URL
ENV DATABASE_URL=$DATABASE_URL

ARG NEXTAUTH_SECRET
ENV NEXTAUTH_SECRET=$NEXTAUTH_SECRET

WORKDIR /app

COPY . .
RUN pwd
RUN ls -la
RUN touch ./apps/web/.env


RUN pnpm install

# Build the project
RUN pnpm post-install --filter=web...
RUN pnpm turbo run build --filter=web...

FROM node:18-alpine AS runner
RUN corepack enable && corepack prepare pnpm@latest --activate

# Don't run production as root
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
USER nextjs

WORKDIR /home/nextjs

COPY --from=installer /app/apps/web/next.config.mjs .
COPY --from=installer /app/apps/web/package.json .

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/standalone ./
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/static ./apps/web/.next/static
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/public ./apps/web/public
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/pre-setup-server.js ./apps/web/pre-setup-server.js
COPY --from=installer --chown=nextjs:nodejs /app/packages/database/schema.prisma ./packages/database/schema.prisma
COPY --from=installer --chown=nextjs:nodejs /app/packages/database/migrations ./packages/database/migrations

EXPOSE 3000

ENV HOSTNAME "0.0.0.0"

CMD if [ "$NEXTAUTH_SECRET" != "RANDOM_STRING" ]; then \
pnpm dlx prisma migrate deploy && \
node apps/web/pre-setup-server.js; \
node apps/web/server.js; \
else \
echo "ERROR: Please set a value for NEXTAUTH_SECRET in your docker compose variables!"; \
exit 1; \
fi
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ services:
restart: always
build:
context: .
dockerfile: ./apps/web/Dockerfile
dockerfile: .
args:
#DATABASE_URL: *database_url
DATABASE_URL: ${DB_CONNECTION_STRING}
Expand Down

0 comments on commit 6e8fdef

Please sign in to comment.