|
| 1 | +# This worklflow will perform following actions when the code is pushed to development branch: |
| 2 | +# - Run end to end test. |
| 3 | +# - Check Linting. |
| 4 | +# - Build the latest docker image in development which needs both e2etest and lint to pass first. |
| 5 | +# - Push the latest docker image to Google Artifact Registry-Dev. |
| 6 | +# - Rollout the latest image in GKE. |
| 7 | +# |
| 8 | +# Maintainers: |
| 9 | +# - name: Nisha Sharma |
| 10 | +# - email: nisha.sharma@uni-jena.de |
| 11 | + |
| 12 | +name : Build and Deploy to Dev |
| 13 | + |
| 14 | +on: |
| 15 | + push: |
| 16 | + branches: [development] |
| 17 | + |
| 18 | +env: |
| 19 | + PROJECT_ID: ${{ secrets.GKE_PROJECT }} |
| 20 | + GKE_CLUSTER_DEV: nmrxiv-dev |
| 21 | + GKE_ZONE: europe-west3-a |
| 22 | + DEPLOYMENT_NAME: nmrxiv-nmrium |
| 23 | + REPOSITORY_NAME_DEV: nmrxiv-dev |
| 24 | + IMAGE: nmrium |
| 25 | + |
| 26 | +jobs: |
| 27 | + e2etest: |
| 28 | + runs-on: ubuntu-latest |
| 29 | + strategy: |
| 30 | + matrix: |
| 31 | + project: [chromium, firefox, webkit] |
| 32 | + fail-fast: false |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v3 |
| 35 | + - uses: actions/setup-node@v3 |
| 36 | + with: |
| 37 | + node-version: 16.x |
| 38 | + - name: Install dependencies |
| 39 | + run: npm ci |
| 40 | + - name: Install Playwright |
| 41 | + run: npx playwright install --with-deps |
| 42 | + - name: Build test application |
| 43 | + env: |
| 44 | + NODE_OPTIONS: '--max_old_space_size=4096' |
| 45 | + run: npm run build-no-minify |
| 46 | + - name: Run E2E tests on ${{ matrix.project }} |
| 47 | + run: npx playwright test --project ${{ matrix.project }} |
| 48 | + continue-on-error: ${{ matrix.project == 'webkit' }} |
| 49 | + |
| 50 | + lint: |
| 51 | + runs-on: ubuntu-latest |
| 52 | + steps: |
| 53 | + - uses: actions/checkout@v2 |
| 54 | + - uses: actions/setup-node@v2 |
| 55 | + with: |
| 56 | + node-version: 16.x |
| 57 | + - name: Install dependencies |
| 58 | + run: npm ci |
| 59 | + - name: Run ESLint |
| 60 | + run: npm run eslint |
| 61 | + - name: Run Prettier |
| 62 | + run: npm run prettier |
| 63 | + - name: Check types |
| 64 | + run: npm run check-types |
| 65 | + |
| 66 | + setup-build-publish-deploy-dev: |
| 67 | + name: Deploy to dev |
| 68 | + if: github.ref == 'refs/heads/development' |
| 69 | + runs-on: ubuntu-latest |
| 70 | + needs: [lint, e2etest] |
| 71 | + steps: |
| 72 | + - name: Checkout |
| 73 | + uses: actions/checkout@v2 |
| 74 | + |
| 75 | + # Setup gcloud CLI |
| 76 | + - name: Setup CLI |
| 77 | + uses: google-github-actions/setup-gcloud@94337306dda8180d967a56932ceb4ddcf01edae7 |
| 78 | + with: |
| 79 | + service_account_key: ${{ secrets.GKE_SA_KEY }} |
| 80 | + project_id: ${{ secrets.GKE_PROJECT }} |
| 81 | + |
| 82 | + # Configure docker to use the gcloud command-line tool as a credential helper |
| 83 | + - name: Configure docker |
| 84 | + run: |- |
| 85 | + gcloud auth configure-docker europe-west3-docker.pkg.dev |
| 86 | +
|
| 87 | + # Get the GKE credentials so we can deploy to the cluster |
| 88 | + - name: Get GKE credentials |
| 89 | + uses: google-github-actions/get-gke-credentials@v0.3.0 |
| 90 | + with: |
| 91 | + cluster_name: ${{ env.GKE_CLUSTER_DEV }} |
| 92 | + location: ${{ env.GKE_ZONE }} |
| 93 | + credentials: ${{ secrets.GKE_SA_KEY }} |
| 94 | + |
| 95 | + # Build the Docker image |
| 96 | + - name: Build docker image |
| 97 | + run: |- |
| 98 | + docker build -f Dockerfile.prod --tag europe-west3-docker.pkg.dev/$PROJECT_ID/$REPOSITORY_NAME_DEV/$IMAGE:latest . |
| 99 | +
|
| 100 | + # Push the Docker image to Google Artifact Registry |
| 101 | + - name: Publish image to Google Artifact Registry |
| 102 | + run: |- |
| 103 | + docker push "europe-west3-docker.pkg.dev/$PROJECT_ID/$REPOSITORY_NAME_DEV/$IMAGE:latest" |
| 104 | +
|
| 105 | + # Deploy the latest Docker image to the GKE cluster |
| 106 | + - name: Deploy |
| 107 | + run: |- |
| 108 | + kubectl rollout restart deployment/$DEPLOYMENT_NAME |
| 109 | + kubectl rollout status deployment/$DEPLOYMENT_NAME --timeout=300s |
| 110 | + kubectl get services -o wide |
0 commit comments