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
111 changes: 111 additions & 0 deletions .github/workflows/aws.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# This workflow will build and push a new container image to Amazon ECR,
# and then will deploy a new task definition to Amazon ECS, when there is a push to the "main" branch.
#
# To use this workflow, you will need to complete the following set-up steps:
#
# 1. Create an ECR repository to store your images.
# For example: `aws ecr create-repository --repository-name my-ecr-repo --region us-east-2`.
# Replace the value of the `ECR_REPOSITORY` environment variable in the workflow below with your repository's name.
# Replace the value of the `AWS_REGION` environment variable in the workflow below with your repository's region.
#
# 2. Create an ECS task definition, an ECS cluster, and an ECS service.
# For example, follow the Getting Started guide on the ECS console:
# https://us-east-2.console.aws.amazon.com/ecs/home?region=us-east-2#/firstRun
# Replace the value of the `ECS_SERVICE` environment variable in the workflow below with the name you set for the Amazon ECS service.
# Replace the value of the `ECS_CLUSTER` environment variable in the workflow below with the name you set for the cluster.
#
# 3. Store your ECS task definition as a JSON file in your repository.
# The format should follow the output of `aws ecs register-task-definition --generate-cli-skeleton`.
# Replace the value of the `ECS_TASK_DEFINITION` environment variable in the workflow below with the path to the JSON file.
# Replace the value of the `CONTAINER_NAME` environment variable in the workflow below with the name of the container
# in the `containerDefinitions` section of the task definition.
#
# 4. Store an IAM user access key in GitHub Actions secrets named `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`.
# See the documentation for each action used below for the recommended IAM policies for this IAM user,
# and best practices on handling the access key credentials.

name: Deploy to Amazon ECS

on:
workflow_run:
workflows: ["Tests"]
types: [completed]

env:
AWS_REGION: eu-north-1 # set this to your preferred AWS region, e.g. us-west-1
ECR_REPOSITORY: lab-repository # set this to your Amazon ECR repository name
ECS_SERVICE: LabManager-task-service-first # set this to your Amazon ECS service name
ECS_CLUSTER: excited-fish # set this to your Amazon ECS cluster name
ECS_TASK_DEFINITION: labman/LabManager-task-definition.json # set this to the path to your Amazon ECS task definition
# file, e.g. .aws/task-definition.json
CONTAINER_NAME: nextjs-lab # set this to the name of the container in the
# containerDefinitions section of your task definition
DATABASE_URL: ${{secrets.DATABASE_URL}}

permissions:
contents: read
id-token: write

jobs:
deploy:
if: >
${{ github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'main' &&
github.event.workflow_run.event == 'push'}}
name: Deploy
runs-on: ubuntu-latest
environment: production

steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha }}

#- name: Configure AWS credentials
# uses: aws-actions/configure-aws-credentials@v1
#with:
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
#aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
#aws-region: ${{ env.AWS_REGION }}

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@main
with:
audience: sts.amazonaws.com
aws-region: ${{ env.AWS_REGION }}
role-to-assume: arn:aws:iam::861353196312:role/ghRole

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

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
pwd
docker build --build-arg DATABASE_URL="$DATABASE_URL" -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./labman
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT

- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ steps.build-image.outputs.image }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ yarn-error.log*
# local env files
.env*.local
.env
.env.production

# vercel
.vercel
Expand Down
1 change: 1 addition & 0 deletions labman/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ yarn-error.log*

# env files (can opt-in for committing if needed)
.env
.env.production

# vercel
.vercel
Expand Down
71 changes: 71 additions & 0 deletions labman/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# syntax=docker.io/docker/dockerfile:1

FROM node:20-alpine AS base

# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi


# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED=1

ARG DATABASE_URL
ENV DATABASE_URL=${DATABASE_URL}

RUN npx prisma generate

RUN \
if [ -f yarn.lock ]; then yarn run build; \
elif [ -f package-lock.json ]; then npm run build; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
else echo "Lockfile not found." && exit 1; \
fi

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app


# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED=1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT=3000

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/config/next-config-js/output
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]
97 changes: 97 additions & 0 deletions labman/LabManager-task-definition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"taskDefinitionArn": "arn:aws:ecs:eu-north-1:861353196312:task-definition/LabManager-task:1",
"containerDefinitions": [
{
"name": "nextjs-lab",
"image": "861353196312.dkr.ecr.eu-north-1.amazonaws.com/lab-repository@sha256:e7cdbf6f8318d5c7a55d534faa467df83a3dd9f9e9663068abef74fd19ff41d1",
"cpu": 0,
"portMappings": [
{
"name": "main",
"containerPort": 3000,
"hostPort": 3000,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"environment": [],
"environmentFiles": [],
"mountPoints": [],
"volumesFrom": [],
"ulimits": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/LabManager-task",
"awslogs-create-group": "true",
"awslogs-region": "eu-north-1",
"awslogs-stream-prefix": "ecs"
},
"secretOptions": []
},
"systemControls": [],
"secrets": [
{
"name": "DATABASE_URL",
"valueFrom": "arn:aws:secretsmanager:eu-north-1:861353196312:secret:lab/prod/db-connection-3F8gP9:DATABASE_URL::"

}
]
}
],
"family": "LabManager-task",
"executionRoleArn": "arn:aws:iam::861353196312:role/ecsTaskExecutionRole",
"networkMode": "awsvpc",
"revision": 1,
"volumes": [],
"status": "ACTIVE",
"requiresAttributes": [
{
"name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
},
{
"name": "ecs.capability.execution-role-awslogs"
},
{
"name": "com.amazonaws.ecs.capability.ecr-auth"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.21"
},
{
"name": "ecs.capability.execution-role-ecr-pull"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
},
{
"name": "ecs.capability.task-eni"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.29"
}
],
"placementConstraints": [],
"compatibilities": [
"EC2",
"FARGATE",
"MANAGED_INSTANCES"
],
"requiresCompatibilities": [
"FARGATE"
],
"cpu": "1024",
"memory": "3072",
"runtimePlatform": {
"cpuArchitecture": "X86_64",
"operatingSystemFamily": "LINUX"
},
"registeredAt": "2026-01-29T14:16:22.647Z",
"registeredBy": "arn:aws:iam::861353196312:root",
"enableFaultInjection": false,
"tags": []
}
5 changes: 3 additions & 2 deletions labman/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ const compat = new FlatCompat({
baseDirectory: __dirname,
});

const eslintConfig = [
// Commented out because it is too strict for auto-generated files from other dependencies
/* const eslintConfig = [
...compat.extends("next/core-web-vitals", "next/typescript"),
];

export default eslintConfig;
export default eslintConfig; */
1 change: 1 addition & 0 deletions labman/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { NextConfig } from "next";

const nextConfig: NextConfig = {
/* config options here */
output: "standalone",
};

export default nextConfig;
4 changes: 2 additions & 2 deletions labman/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"private": true,
"scripts": {
"dev": "next dev --turbopack",
"build": "next build",
"start": "next start",
"build": "dotenv -e .env.production -- next build",
"start": "dotenv -e .env.production -- next start",
"lint": "next lint",
"test": "vitest",
"playwright:test": "dotenv -e .env.test -- next dev --turbopack",
Expand Down
2 changes: 1 addition & 1 deletion labman/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "debian-openssl-3.0.x"]
binaryTargets = ["native", "debian-openssl-3.0.x", "linux-musl-openssl-3.0.x"]
output = "../src/generated/prisma"
}

Expand Down
2 changes: 1 addition & 1 deletion labman/src/app/(auth)/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function Home() {
<form onSubmit={handleSubmit} className="flex flex-col gap-5 pt-4">
<input value={username} onChange={(e) => setUsername(e.target.value)} type="text" name="username" placeholder="Username" className="bg-white rounded-md p-2 m-2 placeholder-black text-black" />
<input value={password} onChange={(e) => setPassword(e.target.value)} type="password" name="password" placeholder="Password" className="bg-white rounded-md p-2 m-2 placeholder-black text-black" />
<button type="submit" className="bg-green-500 text-black rounded-md p-2 m-2">Login</button>
<button type="submit" className="bg-green-500 text-black rounded-md p-2 m-2 font-bold">LOGIN</button>
</form>
</div>

Expand Down
6 changes: 2 additions & 4 deletions labman/src/app/(main)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Metadata } from "next";
import "./globals.css";
import { League_Spartan } from "next/font/google";
import NavBar from "@/components/core/NavBar";
import {PopupProvider} from "./popupProvider"
//import {PopupProvider} from "./popupProvider"
import {getUser} from "@/lib/actions";
import SideBar from "@/components/core/SideBar";

Expand Down Expand Up @@ -38,9 +38,7 @@ export default async function RootLayout({

<main className="flex-1 overflow-auto">
<NavBar username={user?.username ?? "Unknown"} />
<PopupProvider>
{children}
</PopupProvider>
{children}
</main>
</div>
</body>
Expand Down
4 changes: 2 additions & 2 deletions labman/src/app/(main)/popupProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use client"
/*"use client"
import {createContext, useState} from "react";

export const popupContext = createContext(null);
Expand All @@ -19,4 +19,4 @@ export const PopupProvider = ({children}) => {
</>
</popupContext.Provider>
)
}
} */
Loading
Loading