Skip to content

create: enahnced script and project code and docker config #1

create: enahnced script and project code and docker config

create: enahnced script and project code and docker config #1

Workflow file for this run

name: BestCity CI/CD Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
env:
DOCKER_IMAGE: bestcity-app
AWS_REGION: us-east-1
jobs:
lint:
name: Lint Code
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: demo-version/package-lock.json
- name: Install dependencies
run: |
cd demo-version
npm ci
- name: Run ESLint
run: |
cd demo-version
npm run lint || true
test:
name: Run Tests
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: demo-version/package-lock.json
- name: Install dependencies
run: |
cd demo-version
npm ci
- name: Run tests
run: |
cd demo-version
npm test || echo "No tests found"
build:
name: Build Docker Image
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build Docker image
run: |
cd bc-ops
docker build -f docker/Dockerfile -t ${{ env.DOCKER_IMAGE }}:${{ github.sha }} ../demo-version
- name: Test Docker image
run: |
docker run -d --name test-container -p 3099:3099 ${{ env.DOCKER_IMAGE }}:${{ github.sha }}
sleep 10
curl -f http://localhost:3099 || exit 1
docker stop test-container
security-scan:
name: Security Scan
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: 'demo-version'
format: 'sarif'
output: 'trivy-results.sarif'
- name: Upload Trivy results to GitHub Security
uses: github/codeql-action/upload-sarif@v2
if: always()
with:
sarif_file: 'trivy-results.sarif'
deploy-dev:
name: Deploy to Development
runs-on: ubuntu-latest
needs: [build, security-scan]
if: github.ref == 'refs/heads/develop'
environment: development
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
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: Deploy to EC2
run: |
echo "Deployment to development environment"
# Add actual deployment commands here
deploy-prod:
name: Deploy to Production
runs-on: ubuntu-latest
needs: [build, security-scan]
if: github.ref == 'refs/heads/main'
environment: production
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
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 and push Docker image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: bestcity-app
IMAGE_TAG: ${{ github.sha }}
run: |
cd bc-ops
docker build -f Dockerfile -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ../demo-version
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
- name: Deploy to Production EC2
run: |
echo "Deployment to production environment"
# Add actual deployment commands here