This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
chore(deps): bump dset from 3.1.3 to 3.1.4 in /api (#38) #32
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 App | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
- name: Install Amplify CLI | |
run: | | |
npm install -g @aws-amplify/cli | |
- name: Install NPM Dependencies | |
run: | | |
cd api | |
npm install | |
- name: Configure AWS credentials | |
id: aws-credentials | |
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: ${{ secrets.AWS_REGION }} | |
- name: Deploy Amplify Resources | |
run: | | |
cd api | |
export CI=1 | |
npm ci | |
npx ampx pipeline-deploy --branch ${{ github.ref_name }} --app-id ${{ secrets.AMPLIFY_APP_ID }} | |
- name: Generate Amplify Outputs | |
run: | | |
cd api | |
npx ampx generate outputs --format dart --out-dir lib --branch ${{ github.ref_name }} --app-id ${{ secrets.AMPLIFY_APP_ID }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
with: | |
mask-password: true | |
- name: Build, tag, and push image to Amazon ECR | |
id: build-image | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: fluttercon_usa_2024/api-${{ github.ref_name}} | |
IMAGE_TAG: ${{ github.sha }} | |
run: | | |
if ! aws ecr describe-repositories --repository-names $ECR_REPOSITORY 2>/dev/null; then | |
echo "ECR repository does not exist. Creating it..." | |
aws ecr create-repository --repository-name $ECR_REPOSITORY --image-scanning-configuration scanOnPush=true --encryption-configuration encryptionType=AES256 | |
else | |
echo "ECR repository already exists." | |
fi | |
cd api | |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" | |
- name: Generate App Runner service name | |
id: generate-service-name | |
run: | | |
# Remove 'refs/heads/' prefix if present | |
BRANCH_NAME=${GITHUB_REF_NAME#refs/heads/} | |
# Replace invalid characters with hyphens and convert to lowercase | |
SANITIZED_BRANCH=$(echo $BRANCH_NAME | tr '[:upper:]' '[:lower:]' | sed -e 's/[^a-z0-9-]/-/g' -e 's/--*/-/g' -e 's/^-//' -e 's/-$//') | |
# Ensure the name starts with a letter or number | |
if [[ ! $SANITIZED_BRANCH =~ ^[a-z0-9] ]]; then | |
SANITIZED_BRANCH="b-$SANITIZED_BRANCH" | |
fi | |
# Truncate to 40 characters (leaving room for prefix) | |
SANITIZED_BRANCH=${SANITIZED_BRANCH:0:40} | |
# Create the full service name | |
SERVICE_NAME="fluttercon-usa-2024-api-${SANITIZED_BRANCH}" | |
# Truncate the full name to 40 characters if necessary | |
SERVICE_NAME=${SERVICE_NAME:0:40} | |
echo "SERVICE_NAME=$SERVICE_NAME" >> $GITHUB_OUTPUT | |
echo "Generated App Runner service name: $SERVICE_NAME" | |
- name: Deploy to App Runner | |
id: deploy-apprunner | |
uses: awslabs/amazon-app-runner-deploy@main | |
with: | |
service: ${{ steps.generate-service-name.outputs.SERVICE_NAME }} | |
image: ${{ steps.build-image.outputs.image }} | |
access-role-arn: ${{ secrets.ROLE_ARN }} | |
runtime: NODEJS_12 | |
region: ${{ secrets.AWS_REGION }} | |
cpu : 1 | |
memory : 2 | |
port: 8080 | |
wait-for-service-stability-seconds: 600 | |
- name: Get Api URL | |
id: get-app-runner-url | |
run: | | |
SERVICE_ID="${{ steps.deploy-apprunner.outputs.service-id }}" | |
echo "Using Service ID: $SERVICE_ID" | |
# Extract SERVICE_NAME from SERVICE_ID | |
SERVICE_NAME="${{ steps.generate-service-name.outputs.SERVICE_NAME }}" | |
echo "Using: $SERVICE_NAME" | |
# Construct the service ARN | |
AWS_ACCOUNT_ID="${{ secrets.AWS_ACCOUNT_ID }}" | |
AWS_REGION="${{ secrets.AWS_REGION }}" | |
SERVICE_ARN="arn:aws:apprunner:${AWS_REGION}:${AWS_ACCOUNT_ID}:service/${SERVICE_NAME}/${SERVICE_ID}" | |
echo "Constructed Service ARN: $SERVICE_ARN" | |
SERVICE_URL=$(aws apprunner describe-service --service-arn "$SERVICE_ARN" --query 'Service.ServiceUrl' --output text) | |
if [ -z "$SERVICE_URL" ]; then | |
echo "Error: Unable to retrieve Service URL" | |
echo "Full service details:" | |
aws apprunner describe-service --service-arn "$SERVICE_ARN" --output json | |
exit 1 | |
fi | |
echo "API_URL=https://$SERVICE_URL" >> $GITHUB_ENV | |
echo "API URL: $API_URL" | |
- name: Update Amplify Environment Variables | |
run: | | |
echo "Setting BASE_URL to ${API_URL}" | |
aws amplify update-branch --app-id ${{ secrets.AMPLIFY_APP_ID }} --branch ${{ github.ref_name }} --environment-variables BASE_URL=$API_URL | |
- name: Start Amplify Build | |
run: | | |
aws amplify start-job --app-id ${{ secrets.AMPLIFY_APP_ID }} --branch ${{ github.ref_name }} --job-type RELEASE |