From 4ee8196b6b891717ed9803747bc83a54d464931c Mon Sep 17 00:00:00 2001 From: Ebenezer Johnson <68504804+Ebenjohnson@users.noreply.github.com> Date: Sun, 5 Jan 2025 00:40:20 -0800 Subject: [PATCH] Create ci.yml --- .github/workflows/ci.yml | 140 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..1d9a8ba50 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,140 @@ +name: react-portfolio + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x] + mongodb-version: ['6.0'] + + steps: + - uses: actions/checkout@v3 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Start MongoDB + uses: supercharge/mongodb-github-action@1.10.0 + with: + mongodb-version: ${{ matrix.mongodb-version }} + + - name: Install dependencies + run: npm ci + + - name: Run tests + run: npm test + + - name: Run linter + run: npm run lint + + - name: Upload coverage + uses: codecov/codecov-action@v3 + + deploy: + needs: test + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' + + steps: + - uses: actions/checkout@v3 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + + - 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: ngo-website + IMAGE_TAG: ${{ github.sha }} + run: | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + +# Dockerfile +FROM node:18-alpine + +WORKDIR /app + +COPY package*.json ./ +RUN npm ci --only=production + +COPY . . + +EXPOSE 3000 + +CMD ["npm", "start"] + +# docker-compose.yml +version: '3.8' + +services: + app: + build: . + ports: + - "3000:3000" + environment: + - NODE_ENV=production + - MONGODB_URI=${MONGODB_URI} + - REDIS_URL=redis://redis:6379 + depends_on: + - mongodb + - redis + + mongodb: + image: mongo:6.0 + volumes: + - mongodb_data:/data/db + + redis: + image: redis:alpine + volumes: + - redis_data:/data + + prometheus: + image: prom/prometheus + volumes: + - ./prometheus.yml:/etc/prometheus/prometheus.yml + ports: + - "9090:9090" + + grafana: + image: grafana/grafana + ports: + - "3001:3000" + volumes: + - grafana_data:/var/lib/grafana + depends_on: + - prometheus + +volumes: + mongodb_data: + redis_data: + grafana_data: + +# prometheus.yml +global: + scrape_interval: 15s + +scrape_configs: + - job_name: 'ngo-website' + static_configs: + - targets: ['app:3000'] +Last edited 14 days ago