Skip to content

Commit

Permalink
Merge pull request #584 from NYPL/SFR-2403/add-rollback-step
Browse files Browse the repository at this point in the history
SFR-2403: Add rollback step
  • Loading branch information
jackiequach authored Jan 10, 2025
2 parents 9d4bb0a + 7dddbcf commit 5e3b2ea
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 8 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/Playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/build-production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/rollback.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 6 additions & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
@@ -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/",
Expand All @@ -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 */
Expand Down

0 comments on commit 5e3b2ea

Please sign in to comment.