Skip to content

User Staging ECR

User Staging ECR #19

Workflow file for this run

name: User Staging ECR
on:
workflow_dispatch:
env:
SITE_ENV: "user"
LOCAL_ID: ""
ECR_REPOSITORY: "frontend-user-staging"
GA_TRACKING_ID: ""
WORDPRESS_URL: "https://dpla.wpengine.com"
USER_BASE_URL: "https://staging.dp.la"
PRO_BASE_URL: "https://pro.dp.la"
BASE_URL: "https://staging.dp.la"
jobs:
ecr:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Read .nvmrc
run: echo "{NODE_VERSION}={cat .nvmrc}" >> $GITHUB_OUTPUT
id: nvm
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
image: tonistiigi/binfmt:latest
platforms: arm64,arm
- name: Use Node.js ${{ steps.nvm.outputs.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ steps.nvm.outputs.NODE_VERSION }}
- name: Install Yarn
run: npm install -g yarn
- name: Set AWS credentials
if: ${{ !env.ACT }}
uses: aws-actions/configure-aws-credentials@v2
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
if: ${{ !env.ACT }}
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Building the frontend app
- name: Create and populate constants/env.js
run: |
touch constants/env.js
echo "export const SITE_ENV = \"$SITE_ENV\";" >> constants/env.js
echo "export const USER_BASE_URL = \"$USER_BASE_URL\";" >> constants/env.js
echo "export const WORDPRESS_URL = \"$WORDPRESS_URL\";" >> constants/env.js
echo "export const PRO_BASE_URL = \"$PRO_BASE_URL\";" >> constants/env.js
echo "export const LOCAL_ID = \"$LOCAL_ID\";" >> constants/env.js
echo "export const gaTrackingId = \"$GA_TRACKING_ID\";" >> constants/env.js
shell: bash
- name: Add path
run: |
echo "HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin" >> $GITHUB_PATH
shell: bash
- name: Build the app with Yarn
run: |
yarn clean
yarn build
shell: bash
# Get branch names for ECR tagging
- name: Get branch name (merge)
if: github.event_name != 'pull_request'
shell: bash
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
- name: Get branch name (pull request)
if: github.event_name == 'pull_request'
shell: bash
run: echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF} | tr / -)" >> $GITHUB_ENV
# Push to ECR
- name: Build, tag, and push image to Amazon ECR
if: ${{ !env.ACT }}
id: build-image
env:
IMAGE_TAG: ${{ github.sha }}
BRANCH_NAME: ${{ env.BRANCH_NAME }}
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: |
docker buildx build \
-t $ECR_REGISTRY/$ECR_REPOSITORY:latest \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$BRANCH_NAME \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
--platform linux/amd64,linux/arm64 . \
--push