Skip to content

Commit

Permalink
merge two actions
Browse files Browse the repository at this point in the history
  • Loading branch information
haochenpan committed May 29, 2024
1 parent 7a3bab0 commit e183f08
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 115 deletions.
57 changes: 37 additions & 20 deletions .github/workflows/lightsail-deploy-web-service.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy Lightsail Container
name: Deploy Lightsail Containers

on:
push:
Expand All @@ -9,27 +9,44 @@ on:
- lightsail-deploy
workflow_dispatch:
inputs:
service_name:
description: "The name of the Lightsail service"
service_name_1:
description: "The name of the first Lightsail service"
required: true
default: "diaspora-web-service"
container_name:
description: "The name of the Docker container"
container_name_1:
description: "The name of the first Docker container"
required: true
default: "diaspora-web-service-container"
dockerfile_path:
description: "The path to the Dockerfile"
dockerfile_path_1:
description: "The path to the first Dockerfile"
required: true
default: "web_service/Dockerfile"
service_name_2:
description: "The name of the second Lightsail service"
required: true
default: "diaspora-action-provider"
container_name_2:
description: "The name of the second Docker container"
required: true
default: "diaspora-action-provider-container"
dockerfile_path_2:
description: "The path to the second Dockerfile"
required: true
default: "action_provider/Dockerfile"

jobs:
deploy-lightsail-container:
deploy-lightsail-containers:
runs-on: ubuntu-latest

env:
SERVICE_NAME: ${{ github.event.inputs.service_name || 'diaspora-web-service' }}
CONTAINER_NAME: ${{ github.event.inputs.container_name || 'diaspora-web-service-container' }}
DOCKERFILE_PATH: ${{ github.event.inputs.dockerfile_path || 'web_service/Dockerfile' }}
strategy:
matrix:
include:
- service_name: ${{ github.event.inputs.service_name_1 || 'diaspora-web-service' }}
container_name: ${{ github.event.inputs.container_name_1 || 'diaspora-web-service-container' }}
dockerfile_path: ${{ github.event.inputs.dockerfile_path_1 || 'web_service/Dockerfile' }}
- service_name: ${{ github.event.inputs.service_name_2 || 'diaspora-action-provider' }}
container_name: ${{ github.event.inputs.container_name_2 || 'diaspora-action-provider-container' }}
dockerfile_path: ${{ github.event.inputs.dockerfile_path_2 || 'action_provider/Dockerfile' }}

steps:
- name: Configure AWS credentials
Expand All @@ -54,27 +71,27 @@ jobs:
- name: Build Docker container for AWS Lightsail
run: |
echo "SERVICE NAME"
echo $SERVICE_NAME
echo ${{ matrix.service_name }}
echo "CONTAINER NAME"
echo $CONTAINER_NAME
echo ${{ matrix.container_name }}
echo "DOCKERFILE PATH"
echo $DOCKERFILE_PATH
echo ${{ matrix.dockerfile_path }}
docker build -t $CONTAINER_NAME -f $DOCKERFILE_PATH .
docker build -t ${{ matrix.container_name }} -f ${{ matrix.dockerfile_path }} .
docker images
- name: Idempotently Create Lightsail container service
continue-on-error: true
run: |
aws lightsail create-container-service --region us-east-1 --service-name $SERVICE_NAME --power small --scale 1
aws lightsail create-container-service --region us-east-1 --service-name ${{ matrix.service_name }} --power small --scale 1
- name: Push Docker image to Lightsail and deploy
run: |
output=$(aws lightsail push-container-image --region us-east-1 --service-name $SERVICE_NAME --label $CONTAINER_NAME --image $CONTAINER_NAME)
output=$(aws lightsail push-container-image --region us-east-1 --service-name ${{ matrix.service_name }} --label ${{ matrix.container_name }} --image ${{ matrix.container_name }})
image_name=$(echo "$output" | sed -n 's/.*Refer to this image as "\(.*\)" in deployments.*/\1/p')
echo "IMAGE NAME"
echo "$image_name"
Expand All @@ -93,6 +110,6 @@ jobs:
}')
aws lightsail create-container-service-deployment --region us-east-1 \
--service-name $SERVICE_NAME \
--service-name ${{ matrix.service_name }} \
--containers "$containers" \
--public-endpoint "$public_endpoint"
81 changes: 0 additions & 81 deletions .github/workflows/lightsail-deploy.yml

This file was deleted.

12 changes: 0 additions & 12 deletions Dockerfile

This file was deleted.

7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,13 @@ aws lightsail create-container-service-deployment --region us-east-1 \

service_name="diaspora-web-service"
current_container="$service_name-container"
echo $current_container
docker build -t $current_container -f web_service/Dockerfile .
docker run -p 8000:8000 $current_container


service_name="diaspora-action-provider"
current_container="$service_name-container"
docker build -t $current_container -f action_provider/Dockerfile .
docker run -p 8000:8000 $current_container
```

12 changes: 12 additions & 0 deletions action_provider/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM --platform=linux/amd64 python:3.11

EXPOSE 8000/tcp

WORKDIR /diaspora-action-provider

COPY action_provider action_provider
COPY pyproject.toml .

RUN pip install .

CMD [ "python", "action_provider/main.py" ]
2 changes: 1 addition & 1 deletion app/main.py → action_provider/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@app.route('/')
def hello_world():
return "Hello, World from Diaspora Service"
return "Hello, World from Action Provider"

if __name__ == "__main__":
app.run(host='0.0.0.0', port=8000)

0 comments on commit e183f08

Please sign in to comment.