Skip to content

Commit

Permalink
Update deployment workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
object-Object committed Jan 2, 2024
1 parent 8a3a8f8 commit b0a1c7f
Showing 1 changed file with 65 additions and 69 deletions.
134 changes: 65 additions & 69 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ name: Build and deploy

on:
push:
branches:
- "main"
branches: "main"
workflow_dispatch:

env:
Expand All @@ -16,16 +15,13 @@ jobs:
scrape_book_types:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
submodules: "recursive"

- name: Setup Python
uses: actions/setup-python@v4
submodules: recursive
- uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: "pip"
cache: pip

- name: Install Python deps
run: pip install -e .
Expand Down Expand Up @@ -74,15 +70,13 @@ jobs:
iam-role-arn: ${{ steps.cdk-outputs.outputs.iam-role-arn }}
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v3
with:
node-version: 18

- uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: "pip"
cache: pip

- uses: aws-actions/configure-aws-credentials@v4
with:
Expand All @@ -106,63 +100,65 @@ jobs:
echo "deployment-group-name=$(echo "$outputs_json" | jq '.DeploymentGroupName' --raw-output)" >> "$GITHUB_OUTPUT"
echo "iam-role-arn=$(echo "$outputs_json" | jq '.GitHubActionsRoleARN' --raw-output)" >> "$GITHUB_OUTPUT"
# deploy-codedeploy:
# needs: deploy-aws-cdk
# runs-on: ubuntu-latest
# environment:
# name: prod-codedeploy
# url: ${{ steps.create-deployment.outputs.url }}
# permissions:
# id-token: write
# contents: read
# steps:
# - uses: actions/checkout@v4

# - uses: aws-actions/configure-aws-credentials@v4
# with:
# aws-region: ${{ env.AWS_REGION }}
# role-to-assume: ${{ needs.deploy-aws-cdk.outputs.iam-role-arn }}

# - name: Download build artifact
# uses: actions/download-artifact@v3
# with:
# name: build
# path: codedeploy/dist

# - name: Set environment variables
# run: |
# cat <<EOF > codedeploy/.env
# TOKEN="${{ secrets.DISCORD_TOKEN }}"
# LOG_WEBHOOK_URL="${{ secrets.LOG_WEBHOOK_URL }}"
# GITHUB_SHA=main
# GITHUB_REPOSITORY=object-Object/HexBug
# GITHUB_PAGES_URL=https://object-object.github.io/HexBug
# EOF

# - name: Upload deployment bundle to S3
# id: upload-bundle
# run: |
# S3_KEY="${{ env.STACK_NAME }}/${{ github.sha }}.zip"
# echo "s3-key=$S3_KEY" >> "$GITHUB_OUTPUT"
# aws deploy push \
# --application-name ${{ needs.deploy-aws-cdk.outputs.application-name }} \
# --s3-location s3://${{ env.S3_BUCKET }}/$S3_KEY \
# --source codedeploy

# - name: Create CodeDeploy deployment
# id: create-deployment
# run: |
# response="$(aws deploy create-deployment \
# --application-name ${{ needs.deploy-aws-cdk.outputs.application-name }} \
# --deployment-group-name ${{ needs.deploy-aws-cdk.outputs.deployment-group-name }} \
# --s3-location "bucket=${{ env.S3_BUCKET }},key=${{ steps.upload-bundle.outputs.s3-key }},bundleType=zip")"
deploy-codedeploy:
needs: deploy-aws-cdk
runs-on: ubuntu-latest
env:
APPLICATION_NAME: ${{ needs.deploy-aws-cdk.outputs.application-name }}
DEPLOYMENT_GROUP_NAME: ${{ needs.deploy-aws-cdk.outputs.deployment-group-name }}
IAM_ROLE_ARN: ${{ needs.deploy-aws-cdk.outputs.iam-role-arn }}
environment:
name: prod-codedeploy
url: ${{ steps.create-deployment.outputs.url }}
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: ${{ env.IAM_ROLE_ARN }}

- name: Set environment variables
run: |
cat <<EOF > .env
TOKEN="${{ secrets.DISCORD_TOKEN }}"
LOG_WEBHOOK_URL="${{ secrets.LOG_WEBHOOK_URL }}"
GITHUB_SHA=main
GITHUB_REPOSITORY=object-Object/HexBug
GITHUB_PAGES_URL=https://object-object.github.io/HexBug
EOF
- name: Upload deployment bundle to S3
id: upload-bundle
run: |
S3_KEY="${{ env.STACK_NAME }}/${{ github.sha }}.zip"
echo "s3-key=$S3_KEY" >> "$GITHUB_OUTPUT"
aws deploy push \
--application-name ${{ env.APPLICATION_NAME }} \
--s3-location s3://${{ env.S3_BUCKET }}/$S3_KEY \
--source .
- name: Create CodeDeploy deployment
id: create-deployment
run: |
response="$(aws deploy create-deployment \
--application-name ${{ env.APPLICATION_NAME }} \
--deployment-group-name ${{ env.DEPLOYMENT_GROUP_NAME }} \
--s3-location "bucket=${{ env.S3_BUCKET }},key=${{ steps.upload-bundle.outputs.s3-key }},bundleType=zip")"
# deployment_id="$(echo "$response" | jq '.deploymentId' --raw-output)"
# url="https://${{ env.AWS_REGION }}.console.aws.amazon.com/codesuite/codedeploy/deployments/${deployment_id}?region=${{ env.AWS_REGION }}"
# echo "Deployment URL: $url"
deployment_id="$(echo "$response" | jq '.deploymentId' --raw-output)"
url="https://${{ env.AWS_REGION }}.console.aws.amazon.com/codesuite/codedeploy/deployments/${deployment_id}?region=${{ env.AWS_REGION }}"
echo "Deployment URL: $url"
# echo "deployment-id=$deployment_id" >> "$GITHUB_OUTPUT"
# echo "url=$url" >> "$GITHUB_OUTPUT"
echo "deployment-id=$deployment_id" >> "$GITHUB_OUTPUT"
echo "url=$url" >> "$GITHUB_OUTPUT"
# - name: Wait for deployment to finish
# run: aws deploy wait deployment-successful --deployment-id ${{ steps.create-deployment.outputs.deployment-id }}
- name: Wait for deployment to finish
run: |
aws deploy wait deployment-successful \
--deployment-id ${{ steps.create-deployment.outputs.deployment-id }}

0 comments on commit b0a1c7f

Please sign in to comment.