INIT(app): initial commit
- Initialize project structure - Add base configuration
This commit is contained in:
69
.github/workflows/build.yml
vendored
Normal file
69
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
name: Build Docker Image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
tags:
|
||||
- 'v*'
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
IMAGE_NAME: ${{ github.repository }}
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
outputs:
|
||||
image-tag: ${{ steps.meta.outputs.tags }}
|
||||
image-digest: ${{ steps.build.outputs.digest }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Extract metadata (tags, labels)
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
type=ref,event=pr
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=sha,prefix={{branch}}-
|
||||
type=raw,value=latest,enable={{is_default_branch}}
|
||||
|
||||
- name: Build and push Docker image
|
||||
id: build
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: ./services/nextjs
|
||||
file: ./deploy/docker/Dockerfile.prod
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
- name: Display image information
|
||||
run: |
|
||||
echo "✅ Image built and pushed successfully!"
|
||||
echo "📦 Image tags:"
|
||||
echo "${{ steps.meta.outputs.tags }}"
|
||||
echo "🔖 Digest: ${{ steps.build.outputs.digest }}"
|
||||
45
.github/workflows/ci.yml
vendored
Normal file
45
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main, develop]
|
||||
pull_request:
|
||||
branches: [main, develop]
|
||||
|
||||
jobs:
|
||||
lint-and-build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
cache: 'npm'
|
||||
cache-dependency-path: services/nextjs/package-lock.json
|
||||
|
||||
- name: Install dependencies
|
||||
working-directory: services/nextjs
|
||||
run: npm ci
|
||||
|
||||
- name: Run ESLint
|
||||
working-directory: services/nextjs
|
||||
run: npm run lint
|
||||
|
||||
- name: Build Next.js application
|
||||
working-directory: services/nextjs
|
||||
run: npm run build
|
||||
env:
|
||||
NEXT_TELEMETRY_DISABLED: 1
|
||||
|
||||
- name: Check build output
|
||||
working-directory: services/nextjs
|
||||
run: |
|
||||
if [ ! -d ".next" ]; then
|
||||
echo "Build failed: .next directory not found"
|
||||
exit 1
|
||||
fi
|
||||
echo "✅ Build completed successfully"
|
||||
111
.github/workflows/deploy.yml
vendored
Normal file
111
.github/workflows/deploy.yml
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
name: Deploy to Kubernetes
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Build Docker Image"]
|
||||
types:
|
||||
- completed
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
image_tag:
|
||||
description: 'Docker image tag to deploy (e.g., main-abc1234)'
|
||||
required: false
|
||||
default: 'latest'
|
||||
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
IMAGE_NAME: ${{ github.repository }}
|
||||
K8S_NAMESPACE: jovies
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup kubectl
|
||||
uses: azure/setup-kubectl@v3
|
||||
with:
|
||||
version: 'latest'
|
||||
|
||||
- name: Configure kubectl with Lightsail
|
||||
run: |
|
||||
mkdir -p ~/.kube
|
||||
echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > ~/.kube/config
|
||||
chmod 600 ~/.kube/config
|
||||
|
||||
# Verify connection
|
||||
kubectl cluster-info
|
||||
kubectl get nodes
|
||||
|
||||
- name: Determine image tag
|
||||
id: image
|
||||
run: |
|
||||
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
|
||||
TAG="${{ github.event.inputs.image_tag }}"
|
||||
else
|
||||
# Use the commit SHA from the workflow_run event
|
||||
TAG="main-$(echo ${{ github.sha }} | cut -c1-7)"
|
||||
fi
|
||||
|
||||
FULL_IMAGE="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG}"
|
||||
echo "tag=${TAG}" >> $GITHUB_OUTPUT
|
||||
echo "full_image=${FULL_IMAGE}" >> $GITHUB_OUTPUT
|
||||
echo "🐳 Deploying image: ${FULL_IMAGE}"
|
||||
|
||||
- name: Make scripts executable
|
||||
run: |
|
||||
chmod +x ./scripts/common.sh
|
||||
chmod +x ./scripts/k8s-deploy.sh
|
||||
|
||||
- name: Deploy to Kubernetes using script
|
||||
run: |
|
||||
./scripts/k8s-deploy.sh \
|
||||
--namespace ${{ env.K8S_NAMESPACE }} \
|
||||
--no-build \
|
||||
--app-image ${{ steps.image.outputs.full_image }}
|
||||
env:
|
||||
TERM: dumb
|
||||
|
||||
- name: Wait for rollout to complete
|
||||
run: |
|
||||
echo "⏳ Waiting for deployment rollout..."
|
||||
kubectl rollout status deployment/jovies-app \
|
||||
-n ${{ env.K8S_NAMESPACE }} \
|
||||
--timeout=5m
|
||||
|
||||
- name: Verify deployment
|
||||
run: |
|
||||
echo "📊 Deployment status:"
|
||||
kubectl get deployments -n ${{ env.K8S_NAMESPACE }}
|
||||
|
||||
echo ""
|
||||
echo "🔍 Pod status:"
|
||||
kubectl get pods -n ${{ env.K8S_NAMESPACE }}
|
||||
|
||||
echo ""
|
||||
echo "🌐 Service status:"
|
||||
kubectl get services -n ${{ env.K8S_NAMESPACE }}
|
||||
|
||||
- name: Get deployment info
|
||||
run: |
|
||||
echo "✅ Deployment completed!"
|
||||
echo ""
|
||||
echo "📦 Deployed image: ${{ steps.image.outputs.full_image }}"
|
||||
echo "🏷️ Namespace: ${{ env.K8S_NAMESPACE }}"
|
||||
echo ""
|
||||
echo "🔗 Useful commands:"
|
||||
echo " - View logs: kubectl logs -n ${{ env.K8S_NAMESPACE }} -l app=jovies-app -f"
|
||||
echo " - Port forward: kubectl port-forward -n ${{ env.K8S_NAMESPACE }} deploy/jovies-app 3000:3000"
|
||||
echo " - Rollback: kubectl rollout undo deployment/jovies-app -n ${{ env.K8S_NAMESPACE }}"
|
||||
|
||||
- name: Deployment failure notification
|
||||
if: failure()
|
||||
run: |
|
||||
echo "❌ Deployment failed!"
|
||||
echo "Check logs with: kubectl logs -n ${{ env.K8S_NAMESPACE }} -l app=jovies-app"
|
||||
exit 1
|
||||
Reference in New Issue
Block a user