From e183f087f1dd5cb0c0a93085eeb80aa7088a5919 Mon Sep 17 00:00:00 2001 From: Haochen Pan Date: Tue, 28 May 2024 23:27:45 -0400 Subject: [PATCH] merge two actions --- .../lightsail-deploy-web-service.yml | 57 ++++++++----- .github/workflows/lightsail-deploy.yml | 81 ------------------- Dockerfile | 12 --- README.md | 7 +- action_provider/Dockerfile | 12 +++ {app => action_provider}/main.py | 2 +- 6 files changed, 56 insertions(+), 115 deletions(-) delete mode 100644 .github/workflows/lightsail-deploy.yml delete mode 100644 Dockerfile create mode 100644 action_provider/Dockerfile rename {app => action_provider}/main.py (75%) diff --git a/.github/workflows/lightsail-deploy-web-service.yml b/.github/workflows/lightsail-deploy-web-service.yml index ba5ddd3..6d70b6e 100644 --- a/.github/workflows/lightsail-deploy-web-service.yml +++ b/.github/workflows/lightsail-deploy-web-service.yml @@ -1,4 +1,4 @@ -name: Deploy Lightsail Container +name: Deploy Lightsail Containers on: push: @@ -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 @@ -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" @@ -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" diff --git a/.github/workflows/lightsail-deploy.yml b/.github/workflows/lightsail-deploy.yml deleted file mode 100644 index bbbe4f1..0000000 --- a/.github/workflows/lightsail-deploy.yml +++ /dev/null @@ -1,81 +0,0 @@ -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 - - # https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-install-software.html - - 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 for AWS Lightsail - run: | - service_name="diaspora-service" - echo "SERVICE NAME" - echo $service_name - - container_name="$service_name-container" - echo "CONTAINER NAME" - echo $container_name - - docker build -t $container_name -f Dockerfile . - docker images - - - name: Idempotently 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" diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 215abc4..0000000 --- a/Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -FROM --platform=linux/amd64 python:3.11 - -EXPOSE 8000/tcp - -WORKDIR /diaspora-app - -COPY app app -COPY pyproject.toml . - -RUN pip install . - -CMD [ "python", "app/main.py" ] \ No newline at end of file diff --git a/README.md b/README.md index 5186dcb..f4c4bde 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/action_provider/Dockerfile b/action_provider/Dockerfile new file mode 100644 index 0000000..e1716d1 --- /dev/null +++ b/action_provider/Dockerfile @@ -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" ] \ No newline at end of file diff --git a/app/main.py b/action_provider/main.py similarity index 75% rename from app/main.py rename to action_provider/main.py index 2269c0b..3137968 100644 --- a/app/main.py +++ b/action_provider/main.py @@ -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) \ No newline at end of file