Skip to content

Commit 09ee85b

Browse files
committed
feat: add Docker setup with deployment instructions and GitHub Actions workflows
1 parent 5acfbc1 commit 09ee85b

10 files changed

Lines changed: 221 additions & 0 deletions

File tree

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Replace with your GitHub username
2+
GITHUB_USERNAME=your-github-username

.github/workflows/actions.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Build and Push Docker Images
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build_and_push:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v3
15+
16+
- name: Log in to GitHub Container Registry
17+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
18+
19+
- name: Build and push backend image
20+
run: |
21+
docker build ./backend --tag ghcr.io/${{ github.repository_owner }}/task-board:backend-latest
22+
docker push ghcr.io/${{ github.repository_owner }}/task-board:backend-latest
23+
24+
- name: Build and push frontend image
25+
run: |
26+
docker build ./frontend --tag ghcr.io/${{ github.repository_owner }}/task-board:frontend-latest
27+
docker push ghcr.io/${{ github.repository_owner }}/task-board:frontend-latest

DEPLOYMENT.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Docker Deployment Guide
2+
3+
## Setup Instructions
4+
5+
1. **Update Environment Variables**
6+
```bash
7+
# Edit .env file and replace with your GitHub username
8+
GITHUB_USERNAME=your-actual-github-username
9+
```
10+
11+
2. **Deploy on Any Server**
12+
```bash
13+
# Clone repository
14+
git clone https://github.com/your-username/task-board.git
15+
cd task-board
16+
17+
# Update .env with your GitHub username
18+
nano .env
19+
20+
# Pull and start services
21+
docker-compose pull
22+
docker-compose up -d
23+
```
24+
25+
3. **Access Application**
26+
- Frontend: http://your-server-ip
27+
- Backend API: http://your-server-ip:3000
28+
- MongoDB: localhost:27017 (internal)
29+
30+
## Commands
31+
32+
```bash
33+
# Start services
34+
docker-compose up -d
35+
36+
# Stop services
37+
docker-compose down
38+
39+
# View logs
40+
docker-compose logs -f
41+
42+
# Update images
43+
docker-compose pull
44+
docker-compose up -d
45+
```
46+
47+
## Ports
48+
- Frontend: 80
49+
- Backend: 3000
50+
- MongoDB: 27017

backend/.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
node_modules
2+
npm-debug.log
3+
.git
4+
.gitignore
5+
README.md
6+
.env
7+
.nyc_output
8+
coverage
9+
.nyc_output
10+
.coverage
11+
.vscode

backend/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM node:18-alpine
2+
3+
WORKDIR /app
4+
5+
COPY package*.json ./
6+
RUN npm ci --only=production
7+
8+
COPY . .
9+
10+
EXPOSE 3000
11+
12+
CMD ["npm", "start"]

docker-compose.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
version: '3.8'
2+
3+
services:
4+
mongodb:
5+
image: mongo:7
6+
container_name: task-board-mongo
7+
restart: unless-stopped
8+
environment:
9+
MONGO_INITDB_DATABASE: taskboard
10+
volumes:
11+
- mongodb_data:/data/db
12+
ports:
13+
- "27017:27017"
14+
networks:
15+
- task-board-network
16+
17+
backend:
18+
image: ghcr.io/tesfa27/task-board:backend-latest
19+
container_name: task-board-backend
20+
restart: unless-stopped
21+
environment:
22+
- MONGO_URI=mongodb://mongodb:27017/taskboard
23+
- PORT=3000
24+
ports:
25+
- "3000:3000"
26+
depends_on:
27+
- mongodb
28+
networks:
29+
- task-board-network
30+
31+
frontend:
32+
image: ghcr.io/tesfa27/task-board:frontend-latest
33+
container_name: task-board-frontend
34+
restart: unless-stopped
35+
ports:
36+
- "80:80"
37+
depends_on:
38+
- backend
39+
networks:
40+
- task-board-network
41+
42+
volumes:
43+
mongodb_data:
44+
45+
networks:
46+
task-board-network:
47+
driver: bridge

frontend/.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules
2+
npm-debug.log
3+
.git
4+
.gitignore
5+
README.md
6+
.env.local
7+
.vscode
8+
dist
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Build and Push Docker Images
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build_and_push:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v3
15+
16+
- name: Log in to GitHub Container Registry
17+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
18+
19+
- name: Build and push backend image
20+
run: |
21+
docker build ./backend --tag ghcr.io/${{ github.repository_owner }}/task-board:backend-latest
22+
docker push ghcr.io/${{ github.repository_owner }}/task-board:backend-latest
23+
24+
- name: Build and push frontend image
25+
run: |
26+
docker build ./frontend --tag ghcr.io/${{ github.repository_owner }}/task-board:frontend-latest
27+
docker push ghcr.io/${{ github.repository_owner }}/task-board:frontend-latest

frontend/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM node:18-alpine AS build
2+
3+
WORKDIR /app
4+
5+
COPY package*.json ./
6+
RUN npm ci
7+
8+
COPY . .
9+
RUN npm run build
10+
11+
FROM nginx:alpine
12+
13+
COPY --from=build /app/dist /usr/share/nginx/html
14+
COPY nginx.conf /etc/nginx/nginx.conf
15+
16+
EXPOSE 80
17+
18+
CMD ["nginx", "-g", "daemon off;"]

frontend/nginx.conf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
events {
2+
worker_connections 1024;
3+
}
4+
5+
http {
6+
include /etc/nginx/mime.types;
7+
default_type application/octet-stream;
8+
9+
server {
10+
listen 80;
11+
server_name localhost;
12+
root /usr/share/nginx/html;
13+
index index.html;
14+
15+
location / {
16+
try_files $uri $uri/ /index.html;
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)