diff --git a/.github/workflows/Playwright.yml b/.github/workflows/Playwright.yml index 2face764..9d8d2590 100644 --- a/.github/workflows/Playwright.yml +++ b/.github/workflows/Playwright.yml @@ -24,14 +24,16 @@ jobs: - name: Set environment for branch run: | - if [[ github.event.inputs.base_url != '' ]]; then - echo "BASE_URL=${{ github.event.inputs.base_url }}" >> "$GITHUB_ENV" + touch .env + if [[ "${{ github.event.inputs.base_url }}" != '' ]]; then + echo "BASE_URL=${{ github.event.inputs.base_url }}" >> .env else - echo "BASE_URL=http://local.nypl.org:3000/" >> "$GITHUB_ENV" + echo "BASE_URL=http://local.nypl.org:3000/" >> .env fi + shell: bash - name: Add hosts to /etc/hosts - if: github.ref != 'production' + if: github.event_name == 'pull_request' run: | sudo echo "127.0.0.1 local.nypl.org" | sudo tee -a /etc/hosts @@ -45,7 +47,7 @@ jobs: run: NODE_ENV=test npm run build - name: Start the app - if: github.ref != 'production' + if: github.event_name == 'pull_request' run: | NODE_ENV=test npm start & sleep 5 diff --git a/.github/workflows/build-production.yaml b/.github/workflows/build-production.yaml index 53ec4921..10bd1c87 100644 --- a/.github/workflows/build-production.yaml +++ b/.github/workflows/build-production.yaml @@ -29,9 +29,8 @@ jobs: draft: false prerelease: false - publish_qa: + publish_prod: name: Publish image to ECR - if: github.event.pull_request.merged runs-on: ubuntu-latest steps: - name: checkout @@ -68,6 +67,8 @@ jobs: --build-arg NEW_RELIC_APP_NAME="Digital Research Books (PROD)" \ --build-arg NEW_RELIC_LICENSE_KEY=$NEW_RELIC_LICENSE_KEY \ --build-arg NEXT_PUBLIC_ADOBE_ANALYTICS="https://assets.adobedtm.com/1a9376472d37/8519dfce636d/launch-672b7e7f98ee.min.js" . + MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="production-latest" --output json | jq --raw-output --join-output '.images[0].imageManifest') + aws ecr put-image --repository-name $ECR_REPOSITORY --image-tag "production-previous" --image-manifest "$MANIFEST" docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:production-latest docker push $ECR_REGISTRY/$ECR_REPOSITORY:production-latest diff --git a/.github/workflows/rollback.yml b/.github/workflows/rollback.yml new file mode 100644 index 00000000..e84056d8 --- /dev/null +++ b/.github/workflows/rollback.yml @@ -0,0 +1,43 @@ +name: Full CI/CD Pipeline + +on: + workflow_dispatch: + +jobs: + # Rollback job in case of failure (Revert production to the previous task definition) + rollback: + name: Rollback to Previous Version + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version-file: ".nvmrc" + cache: npm + + - name: Configure AWS credentials from Production account + uses: aws-actions/configure-aws-credentials@v4 + 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@v2 + + - name: Pull and tag previous image + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: sfr-front-end + run: | + docker pull $ECR_REGISTRY/$ECR_REPOSITORY:production-previous + docker tag $ECR_REGISTRY/$ECR_REPOSITORY:production-previous $ECR_REGISTRY/$ECR_REPOSITORY:production-latest + docker push $ECR_REGISTRY/$ECR_REPOSITORY:production-latest + + - name: Force ECS Update + run: | + aws ecs update-service --cluster sfr-frontend-production-tf --service sfr-frontend-production-tf --force-new-deployment diff --git a/CHANGELOG.md b/CHANGELOG.md index ac6e88ad..b037f468 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Prerelease] +- Add rollback step to ci/cd yml file + +## [0.18.13] + - Add new yml file for full ci/cd and auto bump version in prod release workflow ## [0.18.12] diff --git a/playwright.config.ts b/playwright.config.ts index db7adc76..58e2bed3 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,4 +1,9 @@ import { devices, PlaywrightTestConfig } from "@playwright/test"; +import dotenv from "dotenv"; +import path from "path"; + +// Read from ".env" file. +dotenv.config({ path: path.resolve(__dirname, ".env") }); const config: PlaywrightTestConfig = { testDir: "playwright/", @@ -24,7 +29,7 @@ const config: PlaywrightTestConfig = { use: { headless: true, // Base URL to use in actions like `await page.goto('/')`. - baseURL: "http://local.nypl.org:3000", + baseURL: process.env.BASE_URL, /* When running tests locally, record a trace for each test, but remove it from successful runs. * On CI, turn this feature off. See https://playwright.dev/docs/trace-viewer */