diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0d82803 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +Dockerfile +.dockerignore +node_modules +npm-debug.log +README.md +.next +docker +.git diff --git a/.env.example b/.env.example index e3e8e03..21137e1 100644 --- a/.env.example +++ b/.env.example @@ -1,8 +1,8 @@ NODE_ENV="development" -DATABASE_URL= +DATABASE_URL=postgresql://postgres:password@localhost:5432/nextauth -NEXTAUTH_SECRET= -NEXTAUTH_URL= +NEXTAUTH_SECRET=your-secret-here +NEXTAUTH_URL=https://sotonverify.link/ # University of Southampton Azure AD Tenant ID - Change only if you want to auth with a different tenant ( ie univerisity account etc ) AZURE_AD_TENANT_ID="4a5378f9-29f4-4d3e-be89-669d03ada9d8" @@ -12,4 +12,4 @@ AZURE_AD_CLIENT_ID= DISCORD_CLIENT_SECRET= DISCORD_CLIENT_ID= -MAIN_BOT_KEY= \ No newline at end of file +MAIN_BOT_KEY= diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..9baf43e --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,35 @@ +name: Docker Image CI + +on: + push: + branches: [ "main" ] + +jobs: + push_to_registry: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ecss/web_sotonverify + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + diff --git a/.github/workflows/nextjs-build.yml b/.github/workflows/nextjs-build.yml new file mode 100644 index 0000000..e386b61 --- /dev/null +++ b/.github/workflows/nextjs-build.yml @@ -0,0 +1,27 @@ +name: Builds Nextjs site + +on: + pull_request: + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: '18.x' + + - run: npm ci + + - name: Lint + run: npm run lint + + - name: Copy environment variables + run: cp .env.example .env + + - run: npm run build diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4f2bcd2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,45 @@ +FROM node:18-alpine AS base + +FROM base AS deps + +WORKDIR /home/node/app + +COPY package.json package-lock.json ./ + +RUN npm ci + +FROM base AS builder + +WORKDIR /home/node/app +COPY --from=deps /home/node/app/node_modules ./node_modules + +COPY . . +COPY .env.example .env + +RUN npm run build + +# 3. Production image, copy all the files and run next +FROM base AS runtime + +WORKDIR /home/node/app + +COPY .env.example .env + +ENV NODE_ENV=production + +RUN addgroup -g 1001 -S nodejs +RUN adduser -S nextjs -u 1001 + +COPY --from=builder /home/node/app/public ./public + +COPY --from=builder --chown=nextjs:nodejs /home/node/app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /home/node/app/.next/static ./.next/static + +USER nextjs + +EXPOSE 3000 + +ENV PORT 3000 +ENV HOSTNAME localhost + +CMD ["node", "server.js"]