Skip to content

Commit

Permalink
debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
yoomlam committed Jun 2, 2024
1 parent 71c6e6e commit f27ae91
Showing 1 changed file with 33 additions and 30 deletions.
63 changes: 33 additions & 30 deletions .github/workflows/push-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ on:
description: 'Tag/Version of the image to push'
required: true
type: string
clear_images:
delete_images:
description: 'Delete previous images in AWS Lightsail'
required: true
type: boolean
default: 'true'

env:
IMAGE_NAME: localimage
Expand All @@ -57,12 +58,14 @@ jobs:
fi
echo "service_name=$service_name" >> $GITHUB_OUTPUT
case "${service_name}" in
# The image_tag is specific to the `*-svc` service
'secure-chatbot-svc') image_tag='0.01';;
'chatbot-chainlit-svc') image_tag='chatbot-chainlit';;
*) echo "Unknown service_name: '${service_name}'"; exit 3;;
esac
image_tag="${{ inputs.image_tag }}"
if [ "${image_tag}" = "" ]; then
case "${service_name}" in
# The image_tag is specific to the `*-svc` service
'secure-chatbot-svc') image_tag='0.01';;
'chatbot-chainlit-svc') image_tag='chatbot-chainlit';;
*) echo "Unknown service_name: '${service_name}'"; exit 3;;
esac
echo "image_tag=$image_tag" >> $GITHUB_OUTPUT
- name: Configure AWS credentials
Expand All @@ -76,25 +79,6 @@ jobs:
# https://github.com/docker/login-action?tab=readme-ov-file#aws-elastic-container-registry-ecr
# https://medium.com/@lukhee/automating-aws-lightsail-deployments-with-github-actions-53c73c9a1c1f

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
mask-password: true

- name: "Checkout source code"
if: inputs.build_image
uses: actions/checkout@v4

- name: "Build image"
if: inputs.build_image
run: |
cd ${{ inputs.dockerfile_folder }}
# TODO: make this more easily editable and secure
# The DOT_ENV_FILE_CONTENTS contains LITERAL_API_KEY, OPENAI_API_KEY, RETRIEVE_K, LLM_MODEL_NAME, SUMMARIZER_LLM_MODEL_NAME
echo "${{secrets.DOT_ENV_FILE_CONTENTS}}" > .env
docker build -t "$IMAGE_NAME" --build-arg GURU_CARDS_URL="https://docs.google.com/uc?export=download&id=${{ secrets.GURU_CARDS_URL_ID }}" .

- name: "Upgrade AWS CLI version and setup lightsailctl"
run: |
Expand All @@ -108,9 +92,8 @@ jobs:
sudo chmod +x /usr/local/bin/lightsailctl
aws lightsail push-container-image help
- name: Clear Container Images
if: ${{ always() && inputs.clear_images == 'true' }}
shell: bash
- name: "Delete previous container images"
if: ${{ always() && inputs.delete_images == 'true' }}
run: |
AWS_IMAGES=$(aws lightsail get-container-images --region ${{ inputs.aws-region }} --service-name ${{ inputs.aws-lightsail-service }} --output text)
IMAGE_NAMES=$(echo $AWS_IMAGES | grep -Eo ':${{ inputs.aws-lightsail-service }}\.${{ inputs.image-name }}\.[0-9]+')
Expand All @@ -123,18 +106,38 @@ jobs:
FIRST=1;
done <<< $IMAGE_NAMES
- name: "Login to Amazon ECR"
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
mask-password: true

- name: "Checkout source code"
if: inputs.build_image
uses: actions/checkout@v4

- name: "Build image"
if: false && inputs.build_image
run: |
cd ${{ inputs.dockerfile_folder }}
# TODO: make this more easily editable and secure
# The DOT_ENV_FILE_CONTENTS contains LITERAL_API_KEY, OPENAI_API_KEY, RETRIEVE_K, LLM_MODEL_NAME, SUMMARIZER_LLM_MODEL_NAME
echo "${{secrets.DOT_ENV_FILE_CONTENTS}}" > .env
docker build -t "$IMAGE_NAME" --build-arg GURU_CARDS_URL="https://docs.google.com/uc?export=download&id=${{ secrets.GURU_CARDS_URL_ID }}" .
- name: "Publish image to Lightsail"
if: inputs.build_image
env:
AWS_REGION: us-east-1
IMAGE_TAG: "${{ steps.check_inputs.outputs.image_tag }}"
IMAGE_SHA_TAG: ${{ github.sha }}
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_PATH: ${{ steps.login-ecr.outputs.registry }}/${{ secrets.ECR_REPO }}
SERVICE_NAME: container-service-2
LABEL: firstLabel
run: |
echo "# Publishing image $SERVICE_NAME $IMAGE_TAG to $ECR_PATH"
echo docker tag "$IMAGE_NAME" "$ECR_PATH:latest"
docker tag "$IMAGE_NAME" "$ECR_PATH:latest"
docker tag "$IMAGE_NAME" "$ECR_PATH:$IMAGE_TAG" .
docker tag "$IMAGE_NAME" "$ECR_PATH:$IMAGE_SHA_TAG" .
Expand Down

0 comments on commit f27ae91

Please sign in to comment.