Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.6 kB
6
Indexable
Never
name: Api extension (api-ext)

on:
  push:
    branches-ignore: [master, staging/setup]

  pull_request:
    types: [closed]
    branches:
      - staging/setup
      - master

jobs:
  pre-deployment:
    if: github.head_ref != 'staging/setup' && github.head_ref != 'master'
    name: Run lint and testing
    runs-on: ubuntu-latest

  # Docker Hub image that `container-job` executes in
    container: node:10.18-jessie

    # Service containers to run with `container-job`
    services:
      # Label used to access the service container
      postgres:
        # Docker Hub image
        image: postgres
        # Provide the password for postgres
        env:
          POSTGRES_PASSWORD: postgres
        # Set health checks to wait until postgres has started
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    defaults:
      run:
        working-directory: ./api-ext

    steps:
      - name: Check out git repository
        uses: actions/checkout@v2

      - name: Set up Node.js
        uses: actions/setup-node@v2
        with:
          node-version: '16'
          cache: 'npm'
          cache-dependency-path: '**/yarn.lock'

      - name: Install nodejs dependencies
        run: npm install --legacy-peer-deps

      - name: Run lint
        run: npm run lint

      - name: Run unit testing
        run: npm run test

      - name: Run e2e testing
        run: npm run test:e2e --verbose
        env:
          DATABASE_HOST: postgres
          DATABASE_USER: postgres
          DATABASE_PASSWORD: postgres
          DATABASE_DATABASE: postgres
          NODE_ENV: test

  deploy-staging:
    # if: github.head_ref == 'staging/setup'
    name: Deploy to staging
    needs: [pre-deployment]
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./api-ext
    steps:
      - name: Check out git repository
        uses: actions/checkout@v3

      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.STAGING_AWS_ACCESS_KEY }}
          aws-secret-access-key: ${{ secrets.STAGING_AWS_SECRET_ACCESS_KEY }}
          aws-region: eu-central-1

      - name: Login to Elastic Container Registry
        id: login-ecr
        uses: aws-actions/amazon-ecr-login@v1

      - name: Build and push image
        env:
          ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
          ECR_REPOSITORY: customer-api
          IMAGE_TAG: latest
        working-directory: ./api-ext
        run: |
          docker build --build-arg APP_VERSION=${{ github.event.inputs.image_tag }} . --file ../Dockerfile.api_ext -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
          docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG    
          echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"

  deploy-production:
    if: github.head_ref == 'master'
    name: Deploy to production
    needs: [pre-deployment]
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./api-ext

    steps:
      - name: Check out git repository
        uses: actions/checkout@v2

      - name: Set up Node.js
        uses: actions/setup-node@v2
        with:
          node-version: '16'
          cache: 'npm'
          cache-dependency-path: '**/yarn.lock'

      - name: Install nodejs dependencies
        run: npm install --legacy-peer-deps

      - name: Run build
        run: npm run build

      - name: Deploying to production
        run: echo "deploying....."