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
97 changes: 97 additions & 0 deletions .aws/fargate-basic-task-revision1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"taskDefinitionArn": "arn:aws:ecs:us-east-2:621180867847:task-definition/fargate-basic-task:1",
"containerDefinitions": [
{
"name": "app",
"image": "621180867847.dkr.ecr.us-east-2.amazonaws.com/portfolio-web-repo:latest",
"cpu": 0,
"portMappings": [
{
"name": "app-80-tcp",
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"restartPolicy": {
"enabled": true,
"restartAttemptPeriod": 300
},
"environment": [],
"environmentFiles": [],
"mountPoints": [],
"volumesFrom": [],
"ulimits": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/fargate-basic-task",
"awslogs-create-group": "true",
"awslogs-region": "us-east-2",
"awslogs-stream-prefix": "ecs"
},
"secretOptions": []
},
"systemControls": []
}
],
"family": "fargate-basic-task",
"taskRoleArn": "arn:aws:iam::621180867847:role/ecsTaskExecutionRole",
"executionRoleArn": "arn:aws:iam::621180867847: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": "ecs.capability.container-restart-policy"
},
{
"name": "com.amazonaws.ecs.capability.task-iam-role"
},
{
"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"
],
"requiresCompatibilities": [
"FARGATE"
],
"cpu": "1024",
"memory": "3072",
"runtimePlatform": {
"cpuArchitecture": "X86_64",
"operatingSystemFamily": "LINUX"
},
"registeredAt": "2025-08-04T18:34:06.217Z",
"registeredBy": "arn:aws:iam::621180867847:user/and-aws_@856",
"enableFaultInjection": false,
"tags": []
}
92 changes: 92 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# 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: CD Pipeline Amazon ECS

on:
push:
branches: ["main"]

env:
AWS_REGION: us-east-2
ECR_REPOSITORY: portfolio-web-repo
ECS_SERVICE: fargate-basic-service-portfolio
ECS_CLUSTER: portfolio-web-cluster
ECS_TASK_DEFINITION: .aws/fargate-basic-task-revision1.json
CONTAINER_NAME: app

permissions:
contents: read

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production

steps:
- name: Checkout
uses: actions/checkout@v4

- 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: 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.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
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@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI Pipeline
on:
push:
branches:
- staging
- main
pull_request:
branches:
- main
workflow_dispatch:
inputs:
branch_name:
description: "Branch to run tests"
required: true
default: "staging"

jobs:
test:
runs-on: ubuntu-latest
name: Building and Testing
steps:
- uses: actions/checkout@v4

- name: Create NodeJS env
uses: actions/setup-node@v4
with:
node-version: 22.x

- name: Install packages
run: npm ci && npm ci --prefix frontend && npm ci --prefix backend

- name: Run tests
run: npm test
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ node_modules/
frontend/node_modules/
frontend/dist/
frontend/TODO.md
frontend/coverage

backend/node_modules/
backend/node_modules/
backend/coverage
backend/logs/
backend/uploads
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# My Portfolio Website
[![CI Pipeline](https://github.com/arauta12/MyWebsite/actions/workflows/ci.yml/badge.svg)](https://github.com/arauta12/MyWebsite/actions/workflows/ci.yml)
36 changes: 31 additions & 5 deletions backend/app.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,56 @@
const express = require('express');
const helmet = require('helmet');
const cors = require('cors');

const cookieParser = require('cookie-parser');
const morgan = require('morgan');
const path = require('path');
const fs = require('fs');

const authRoute = require('./routes/auth.route');
const userRoute = require('./routes/user.route');
const projectRoute = require('./routes/project.route');
const messageRoute = require('./routes/message.route');
const uploadRoute = require('./routes/uploads.route');

const app = express();

const whitelist = [
"http://localhost:3000",
"http://localhost:5173",
"http://localhost:8080",
];
const corsConfig = {
origin: [
"http://localhost:3000",
"http://localhost:5173",
],
origin: whitelist,
credentials: true,
optionsSuccessStatus: 200
};

const createLogName = () => {
const logDate = new Date(Date.now());
const logName = `${logDate.getUTCMonth()}-${logDate.getUTCDay()}-${logDate.getUTCFullYear()}.log`;
console.log(logName);

return path.join(__dirname, 'logs', logName);
};

const logStream = fs.createWriteStream(
createLogName(),
{ autoClose: true, emitClose: false, flags: 'a' }
);

const logger = morgan("combined", { immediate: true, stream: logStream });

app.use(logger);
app.use(cors(corsConfig));
app.use(helmet());
app.use(express.json());
app.use(cookieParser());

app.use('/api/auth', authRoute);
app.use('/api/projects', projectRoute);
app.use('/api/messages', messageRoute);
app.use('/api/users', userRoute);
// app.use('/api/uploads', uploadRoute);

app.all('{*splat}', (req, res) => {
res.status(404).send('That resource does not exist!');
Expand Down
Loading