Fix so buildspec.yaml gets written before being committed. #27
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Publish Service Lambda | |
on: | |
push: | |
paths: | |
- 'toolkit-service-lambda/**' | |
branches: | |
- '**' | |
workflow_dispatch: | |
jobs: | |
build-and-publish: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Determine Branch Name | |
id: branch_name | |
run: | | |
BRANCH_NAME=${GITHUB_REF#refs/heads/} | |
BRANCH_NAME_SAFE=${BRANCH_NAME//\//-} | |
if [ "$BRANCH_NAME" = "main" ]; then | |
tag_suffix="" | |
is_main=true | |
else | |
tag_suffix="-$BRANCH_NAME_SAFE" | |
is_main=false | |
fi | |
echo "tag_suffix=$tag_suffix" >> $GITHUB_ENV | |
echo "is_main=$is_main" >> $GITHUB_ENV | |
- name: Configure AWS Credentials | |
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-west-2 | |
- name: Log in to Amazon ECR | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: us-west-2 | |
run: | | |
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin 211125507740.dkr.ecr.$AWS_REGION.amazonaws.com | |
- name: Build Docker image | |
run: | | |
cd toolkit-service-lambda | |
docker build -t service-handler-image:latest . | |
- name: Tag Docker image for ECR | |
run: | | |
if [ "$is_main" = "true" ]; then | |
docker tag service-handler-image:latest 211125507740.dkr.ecr.us-west-2.amazonaws.com/industry-toolkit/service-lambda-handler:latest | |
fi | |
docker tag service-handler-image:latest 211125507740.dkr.ecr.us-west-2.amazonaws.com/industry-toolkit/service-lambda-handler:latest${{ env.tag_suffix }} | |
- name: Push Docker image to ECR | |
run: | | |
if [ "$is_main" = "true" ]; then | |
docker push 211125507740.dkr.ecr.us-west-2.amazonaws.com/industry-toolkit/service-lambda-handler:latest | |
fi | |
docker push 211125507740.dkr.ecr.us-west-2.amazonaws.com/industry-toolkit/service-lambda-handler:latest${{ env.tag_suffix }} |