Skip to content

Merge pull request #10 from mravinale/mravinale-patch-2 #58

Merge pull request #10 from mravinale/mravinale-patch-2

Merge pull request #10 from mravinale/mravinale-patch-2 #58

Workflow file for this run

name: node-starter
on:
push:
branches:
- main
- release/*
- aws-ecs
pull_request:
branches:
- main
workflow_dispatch:
env:
ECR_REPOSITORY: public.ecr.aws/b1x7g5t5/node-starter
ECS_SERVICE: node-starter
ECS_CLUSTER: node-starter
ECS_TASK_DEFINITION: .github/workflows/task-definition.json
ECS_CONTAINER_NAME: node-starter
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Run tests
run: yarn test
aws:
if: ${{ github.ref == 'refs/heads/main' }}
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Login to ECR public
shell: bash
run: docker run -e AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} -e AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} -e us-east-1 amazon/aws-cli ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin ${{ env.ECR_REPOSITORY }}
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ env.ECR_REPOSITORY }}
IMAGE_TAG: ${{ github.sha }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REPOSITORY:latest .
docker push $ECR_REPOSITORY:latest
echo "::set-output name=image::$ECR_REPOSITORY:latest"
echo "ecr-registry:ECR_REGISTRY"
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
container-name: ${{ env.ECS_CONTAINER_NAME }}
image: ${{ steps.build-image.outputs.image }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true