Merge pull request #21 from dabigjoe6/fix-openai-model #46
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: Deploy with AWS CDK | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
env: | |
FUNCTION_NAME: ${{ vars.FUNCTION_NAME_STAGING }} | |
BASE_URL: ${{ vars.BASE_URL_STAGING }} | |
FROM: ${{ vars.FROM_STAGING }} | |
NO_OF_POSTS_SENT_TO_USERS: ${{ vars.NO_OF_POSTS_SENT_TO_USERS_STAGING }} | |
OPENAI_API_KEY: ${{ vars.OPENAI_API_KEY }} | |
SENDGRID_API_KEY: ${{ vars.SENDGRID_API_KEY }} | |
SYNC_HOURS: ${{ vars.SYNC_HOURS_STAGING }} | |
AWS_ECR_REGISTRY: ${{ vars.AWS_ECR_REGISTRY }} | |
steps: | |
- name: Print Set Environment variables | |
run: | | |
echo "FUNCTION_NAME: $FUNCTION_NAME" | |
echo "BASE_URL: $BASE_URL" | |
echo "FROM: $FROM" | |
echo "NO_OF_POSTS_SENT_TO_USERS: $NO_OF_POSTS_SENT_TO_USERS" | |
echo "OPENAI_API_KEY: $OPENAI_API_KEY" | |
echo "SENDGRID_API_KEY: $SENDGRID_API_KEY" | |
echo "SYNC_HOURS: $SYNC_HOURS" | |
echo "AWS_ECR_REGISTRY: $AWS_ECR_REGISTRY" | |
transformed_text=$(echo "$FUNCTION_NAME" | sed -E 's/(^|_)(\w)/\U\2/g') | |
transformed_text+="Stack" | |
export STACK_NAME=$transformed_text | |
echo STACK_NAME: $STACK_NAME | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- 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: eu-west-2 | |
- name: Login to AWS ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Build, tag, and push image to Amazon ECR | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: ${{ env.FUNCTION_NAME }} | |
IMAGE_TAG: ${{ github.sha }} | |
run: | | |
echo "ECR_REGISTRY: $ECR_REGISTRY" | |
echo "ECR_REPOSITORY: $ECR_REPOSITORY" | |
echo "IMAGE_TAG: $IMAGE_TAG" | |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: 14 | |
- name: Install CDK dependencies | |
run: npm ci | |
- name: Deploy CDK stack | |
run: npx cdk deploy $STACK_NAME --require-approval never | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: eu-west-2 | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: ${{ env.FUNCTION_NAME }} | |
IMAGE_TAG: ${{ github.sha }} |