Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/container containerised and CI SETUP #2

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
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
63 changes: 63 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: CI

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '22'
- name: Install dependencies frontend
run: |
cd frontend
yarn install

- name: Run linting frontend
run: |
cd frontend
yarn lint

- name: build frontend
run: |
cd frontend
docker build . -t ${{secrets.DOCKER_HUB_USERNAME}}/sample-fullstack-application-frontend

- name: install dependencies backend
run: |
cd backend
yarn install

- name: Run linting and tests backend
run: |
cd backend
yarn test

- name: build backend
run: |
cd backend
docker build . -t ${{secrets.DOCKER_HUB_USERNAME}}/sample-fullstack-application-backend

- name: login to docker hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: PUSH ARTIFACTS
run: |
docker push ${{secrets.DOCKER_HUB_USERNAME}}/sample-fullstack-application-frontend
docker push ${{secrets.DOCKER_HUB_USERNAME}}/sample-fullstack-application-backend




6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# Sample Fullstack Application
Run using docker
Set the environment variables using .env refer sampl.env

```
docker compose up -d
```
VISIT http://localhost
30 changes: 30 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Ignore node_modules and yarn cache
node_modules
yarn-error.log
yarn.lock

# Ignore TypeScript build artifacts
/dist
/.build
/.vscode

# Ignore development files
*.log
*.test.ts
*.spec.ts

# Ignore version control files
.git
.gitignore

# Ignore Docker-related files
Dockerfile
docker-compose.yml
.dockerignore

# Ignore IDE and editor-specific files
.idea
.vscode
*.sublime-project
*.sublime-workspace

36 changes: 36 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Stage 1: Build Stage
FROM node:22-alpine AS build

WORKDIR /app

COPY package.json .
RUN yarn install

# Copy the rest of the application code
COPY . .

RUN npx prisma generate

# Build the application
RUN yarn build

# Stage 2: Production Stage
FROM node:22-alpine

# Set working directory
WORKDIR /app

# Copy built artifacts from the previous stage
COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/prisma ./prisma
COPY --from=build /app/package.json .
COPY ./entrypoint.sh .


# Expose the port the app runs on
EXPOSE 3000

# Command to run your Nest.js application using production mode
CMD ["node", "dist/main"]

16 changes: 16 additions & 0 deletions backend/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

check_postgres() {
echo "Checking PostgreSQL status..."
nc -z postgres 5432
}

# Wait until PostgreSQL is ready
until check_postgres; do
echo "PostgreSQL is unavailable - sleeping"
sleep 1
done

echo "PostgreSQL is up - executing command"

yarn run start:prod
Loading