Skip to content

Update lightsail-deploy.yml #5

Update lightsail-deploy.yml

Update lightsail-deploy.yml #5

name: Deploy Lightsail Container
on:
push:
branches:
- lightsail-deploy
pull_request:
branches:
- lightsail-deploy
jobs:
deploy-lightsail-container:
runs-on: ubuntu-latest
steps:
- name: Configure 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: us-east-1
- name: Verify AWS credential
run: |
aws sts get-caller-identity
- name: Install AWS Lightsail plugin
run: |
sudo curl "https://s3.us-west-2.amazonaws.com/lightsailctl/latest/linux-amd64/lightsailctl" -o "/usr/local/bin/lightsailctl"
sudo chmod +x /usr/local/bin/lightsailctl
- name: Checkout code
uses: actions/checkout@v4
- name: Build Docker container
run: |
service_name="diaspora-service"
container_name="$service_name-container"
echo $service_name
echo $container_name
docker build -t $container_name -f Dockerfile .
docker images
- name: Create Lightsail container service
continue-on-error: true
run: |
service_name="diaspora-service"
aws lightsail create-container-service --region us-east-1 --service-name $service_name --power small --scale 1
- name: Push Docker image to Lightsail and deploy
run: |
service_name="diaspora-service"
container_name="$service_name-container"
output=$(aws lightsail push-container-image --region us-east-1 --service-name $service_name --label $container_name --image $container_name)
image_name=$(echo "$output" | sed -n 's/.*Refer to this image as "\(.*\)" in deployments.*/\1/p')
echo "IMAGE NAME"
echo "$image_name"
containers=$(jq -n --arg image_name "$image_name" '{
"flask": {
"image": $image_name,
"ports": {
"8000": "HTTP"
}
}
}')
public_endpoint=$(jq -n '{
"containerName": "flask",
"containerPort": 8000
}')
aws lightsail create-container-service-deployment --region us-east-1 \
--service-name $service_name \
--containers "$containers" \
--public-endpoint "$public_endpoint"