Skip to content

Commit 35aa14f

Browse files
committed
Update to refactor
1 parent 534e7b1 commit 35aa14f

File tree

6 files changed

+273
-144
lines changed

6 files changed

+273
-144
lines changed

.github/workflows/README.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# GitHub Actions Workflows
2+
3+
## Build and Push Docker Images
4+
5+
This workflow automatically builds and pushes Docker images to GitHub Container Registry (GHCR) when code is pushed to the `main` branch or when version tags are created.
6+
7+
### Triggers
8+
9+
- **Push to main branch**: Builds and tags as `latest`
10+
- **Version tags** (e.g., `v1.0.0`): Builds with semantic versioning tags
11+
12+
### Required Secrets
13+
14+
You need to configure the following secrets in your GitHub repository settings:
15+
16+
1. **`GITHUB_TOKEN`** (automatically provided by GitHub)
17+
- Used to authenticate with GitHub Container Registry
18+
- No manual setup required
19+
20+
2. **`INFRA_REPO_TOKEN`** (required for deployment trigger)
21+
- Personal Access Token (PAT) with `repo` scope
22+
- Used to trigger deployment in infrastructure repository
23+
- Create at: https://github.com/settings/tokens
24+
25+
3. **`INFRA_REPO_OWNER`** (required)
26+
- GitHub username or organization that owns the infrastructure repo
27+
- Example: `your-username` or `your-org`
28+
29+
4. **`INFRA_REPO_NAME`** (required)
30+
- Name of your infrastructure repository
31+
- Example: `amar-pathagar-infra`
32+
33+
### Setup Instructions
34+
35+
1. **Enable GitHub Container Registry**
36+
```bash
37+
# Make sure your repository has packages enabled
38+
# Go to: Settings > Actions > General > Workflow permissions
39+
# Enable: "Read and write permissions"
40+
```
41+
42+
2. **Add Required Secrets**
43+
```bash
44+
# Go to: Settings > Secrets and variables > Actions > New repository secret
45+
46+
# Add INFRA_REPO_TOKEN
47+
# - Name: INFRA_REPO_TOKEN
48+
# - Value: Your GitHub Personal Access Token
49+
50+
# Add INFRA_REPO_OWNER
51+
# - Name: INFRA_REPO_OWNER
52+
# - Value: your-github-username
53+
54+
# Add INFRA_REPO_NAME
55+
# - Name: INFRA_REPO_NAME
56+
# - Value: amar-pathagar-infra
57+
```
58+
59+
3. **Create a Personal Access Token**
60+
- Go to: https://github.com/settings/tokens
61+
- Click "Generate new token (classic)"
62+
- Select scopes: `repo` (full control of private repositories)
63+
- Copy the token and add it as `INFRA_REPO_TOKEN` secret
64+
65+
### Workflow Steps
66+
67+
1. **Checkout code**: Clones the repository
68+
2. **Set up Docker Buildx**: Enables advanced Docker build features
69+
3. **Login to GHCR**: Authenticates with GitHub Container Registry
70+
4. **Extract metadata**: Generates Docker tags and labels
71+
5. **Build and push**: Builds multi-platform images (amd64, arm64) and pushes to GHCR
72+
6. **Trigger deployment**: Sends webhook to infrastructure repo for staging deployment
73+
74+
### Image Tags
75+
76+
The workflow creates the following tags:
77+
78+
- `latest` - Latest build from main branch
79+
- `main-<sha>` - Commit SHA from main branch
80+
- `v1.0.0` - Semantic version (when tagged)
81+
- `1.0` - Major.minor version (when tagged)
82+
83+
### Usage
84+
85+
**Push to main branch:**
86+
```bash
87+
git add .
88+
git commit -m "feat: add new feature"
89+
git push origin main
90+
```
91+
92+
**Create version tag:**
93+
```bash
94+
git tag v1.0.0
95+
git push origin v1.0.0
96+
```
97+
98+
### Pulling Images
99+
100+
```bash
101+
# Pull latest image
102+
docker pull ghcr.io/your-username/amar-pathagar-frontend:latest
103+
104+
# Pull specific version
105+
docker pull ghcr.io/your-username/amar-pathagar-frontend:v1.0.0
106+
```
107+
108+
### Troubleshooting
109+
110+
**Error: "Resource not accessible by integration"**
111+
- Go to Settings > Actions > General > Workflow permissions
112+
- Enable "Read and write permissions"
113+
114+
**Error: "Failed to trigger deployment"**
115+
- Check that `INFRA_REPO_TOKEN` has correct permissions
116+
- Verify `INFRA_REPO_OWNER` and `INFRA_REPO_NAME` are correct
117+
- Ensure the infrastructure repo exists and is accessible
118+
119+
**Build fails on arm64**
120+
- This is normal if you don't need arm64 support
121+
- Remove `linux/arm64` from platforms in the workflow file
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Build and Push Docker Images
2+
3+
on:
4+
push:
5+
branches: [main]
6+
tags:
7+
- 'v*.*.*'
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
20+
steps:
21+
- name: 📥 Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: 🔧 Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v3
26+
27+
- name: 🔐 Login to GitHub Container Registry
28+
uses: docker/login-action@v3
29+
with:
30+
registry: ${{ env.REGISTRY }}
31+
username: ${{ github.actor }}
32+
password: ${{ secrets.GITHUB_TOKEN }}
33+
34+
- name: 🏷️ Extract metadata
35+
id: meta
36+
uses: docker/metadata-action@v5
37+
with:
38+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
39+
tags: |
40+
type=ref,event=branch
41+
type=semver,pattern={{version}}
42+
type=semver,pattern={{major}}.{{minor}}
43+
type=sha,prefix={{branch}}-
44+
type=raw,value=latest,enable={{is_default_branch}}
45+
46+
- name: 🐳 Build and push Docker image
47+
uses: docker/build-push-action@v5
48+
with:
49+
context: .
50+
push: true
51+
tags: ${{ steps.meta.outputs.tags }}
52+
labels: ${{ steps.meta.outputs.labels }}
53+
cache-from: type=gha
54+
cache-to: type=gha,mode=max
55+
platforms: linux/amd64,linux/arm64
56+
57+
- name: 🚀 Trigger Infrastructure Staging Deployment
58+
if: success() && github.ref == 'refs/heads/main'
59+
run: |
60+
curl -X POST \
61+
-H "Authorization: token ${{ secrets.INFRA_REPO_TOKEN }}" \
62+
-H "Accept: application/vnd.github.v3+json" \
63+
https://api.github.com/repos/${{ secrets.INFRA_REPO_OWNER }}/${{ secrets.INFRA_REPO_NAME }}/dispatches \
64+
-d '{"event_type":"deploy-frontend-staging","client_payload":{"image_tag":"${{ steps.meta.outputs.version }}"}}'
65+
66+
- name: 🎉 Deployment triggered
67+
if: success() && github.ref == 'refs/heads/main'
68+
run: |
69+
echo "✅ Frontend image built and pushed successfully!"
70+
echo "🚀 Infrastructure deployment triggered for staging environment"
71+
echo "📦 Image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest"

Dockerfile.dev

Lines changed: 0 additions & 18 deletions
This file was deleted.

Makefile

Lines changed: 12 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -15,118 +15,31 @@ help: ## Show this help message
1515
@echo ""
1616
@echo "Usage: make [target]"
1717
@echo ""
18-
@grep -hE '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
19-
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
18+
@grep -hE '^[a-zA-Z_-]+:.*?## .*$' $(MAKEFILE_LIST) | sort | \
19+
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $1, $2}'
2020

2121
# --------------------------------------------------
22-
# Development
22+
# Development (Local)
2323
# --------------------------------------------------
2424
.PHONY: dev
25-
dev: ## Start development server (local)
25+
dev: ## Start development server locally
2626
npm run dev
2727

28-
.PHONY: dev-docker
29-
dev-docker: ## Start development server (Docker with hot reload)
30-
docker compose -f docker-compose.dev.yml up -d
31-
@echo "✅ Development server started"
32-
@echo "📝 Frontend: http://localhost:3000"
33-
@echo "📋 Logs: make logs"
34-
3528
.PHONY: install
3629
install: ## Install dependencies
3730
npm install
38-
@echo "✅ Dependencies installed"
39-
40-
.PHONY: logs
41-
logs: ## Follow application logs (Docker)
42-
docker compose -f docker-compose.dev.yml logs -f frontend
43-
44-
.PHONY: restart
45-
restart: ## Restart development server (Docker)
46-
docker compose -f docker-compose.dev.yml restart frontend
47-
@echo "✅ Frontend restarted"
48-
49-
.PHONY: stop
50-
stop: ## Stop development server (Docker)
51-
docker-compose -f docker-compose.dev.yml stop
5231

5332
# --------------------------------------------------
5433
# Production
5534
# --------------------------------------------------
5635
.PHONY: build
57-
build: ## Build for production (local)
58-
npm run build
59-
@echo "✅ Production build complete"
60-
61-
.PHONY: start
62-
start: ## Start production server (local)
63-
npm start
64-
65-
.PHONY: up
66-
up: ## Start production server (Docker)
67-
docker-compose -f docker-compose.yml up -d --build
68-
@echo "✅ Production server started"
69-
70-
.PHONY: down
71-
down: ## Stop and remove all containers
72-
docker-compose -f docker-compose.yml down
73-
docker-compose -f docker-compose.dev.yml down
74-
@echo "✅ All containers stopped and removed"
75-
76-
# --------------------------------------------------
77-
# Code Quality
78-
# --------------------------------------------------
79-
.PHONY: lint
80-
lint: ## Run linter
81-
npm run lint
82-
@echo "✅ Linting complete"
83-
84-
.PHONY: type-check
85-
type-check: ## Run TypeScript type checking
86-
npx tsc --noEmit
87-
@echo "✅ Type checking complete"
88-
89-
# --------------------------------------------------
90-
# Docker Utilities
91-
# --------------------------------------------------
92-
.PHONY: ps
93-
ps: ## Show running containers
94-
docker-compose -f docker-compose.dev.yml ps
95-
96-
.PHONY: shell
97-
shell: ## Open shell in frontend container
98-
docker-compose -f docker-compose.dev.yml exec frontend sh
36+
build: ## Build production Docker image
37+
docker build -t amar-pathagar-frontend:latest .
9938

100-
.PHONY: clean
101-
clean: ## Clean up containers, volumes, and build artifacts
102-
docker-compose -f docker-compose.yml down -v
103-
docker-compose -f docker-compose.dev.yml down -v
104-
rm -rf .next
105-
rm -rf node_modules
106-
@echo "✅ Cleanup complete"
39+
.PHONY: prod
40+
prod: ## Start production environment
41+
docker compose up -d
10742

108-
.PHONY: clean-cache
109-
clean-cache: ## Clean Next.js cache
110-
rm -rf .next
111-
@echo "✅ Cache cleaned"
112-
113-
# --------------------------------------------------
114-
# Info
115-
# --------------------------------------------------
116-
.PHONY: info
117-
info: ## Show project information
118-
@echo "╔════════════════════════════════════════════════════════════╗"
119-
@echo "║ Amar Pathagar Frontend Info ║"
120-
@echo "╚════════════════════════════════════════════════════════════╝"
121-
@echo ""
122-
@echo "📦 Project: Amar Pathagar Frontend"
123-
@echo "🔧 Framework: Next.js 14"
124-
@echo "⚛️ React: 18"
125-
@echo "📘 TypeScript: 5"
126-
@echo ""
127-
@echo "🌐 Endpoints:"
128-
@echo " - Development: http://localhost:3000"
129-
@echo " - API: Check .env.local"
130-
@echo ""
131-
@echo "📚 Documentation: README.md"
132-
@echo ""
43+
.PHONY: prod-down
44+
prod-down: ## Stop production environment
45+
docker compose down

0 commit comments

Comments
 (0)