-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
140 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: Docker Publish | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
tags: ["v*.*.*"] | ||
pull_request: | ||
branches: ["main"] | ||
|
||
env: | ||
REGISTRY: docker.io | ||
IMAGE_NAME: eibrahim/fluid-calendar | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Log into Docker Hub | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Extract Docker metadata | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
tags: | | ||
type=ref,event=branch | ||
type=ref,event=pr | ||
type=semver,pattern={{version}} | ||
type=semver,pattern={{major}}.{{minor}} | ||
type=sha | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: docker/production/Dockerfile | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
platforms: linux/amd64,linux/arm64 | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Build stage | ||
FROM node:20-alpine AS builder | ||
|
||
WORKDIR /app | ||
|
||
# Install dependencies | ||
COPY package*.json ./ | ||
COPY prisma ./prisma/ | ||
|
||
# Install dependencies and generate Prisma client | ||
RUN npm ci | ||
RUN npx prisma generate | ||
|
||
# Copy source | ||
COPY . . | ||
|
||
# Build application | ||
RUN npm run build | ||
|
||
# Production stage | ||
FROM node:20-alpine AS runner | ||
|
||
WORKDIR /app | ||
|
||
# Install production dependencies | ||
COPY --from=builder /app/package*.json ./ | ||
RUN npm ci --only=production | ||
|
||
# Copy built application | ||
COPY --from=builder /app/.next ./.next | ||
COPY --from=builder /app/public ./public | ||
COPY --from=builder /app/prisma ./prisma | ||
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma | ||
|
||
# Create and switch to non-root user | ||
RUN addgroup --system --gid 1001 nodejs | ||
RUN adduser --system --uid 1001 nextjs | ||
USER nextjs | ||
|
||
# Expose port | ||
EXPOSE 3000 | ||
|
||
# Set environment variables | ||
ENV NODE_ENV=production | ||
ENV NEXT_TELEMETRY_DISABLED=1 | ||
|
||
# Start the application | ||
CMD ["npm", "start"] |