CasaOS/.github/workflows/demo.yml

80 lines
3.3 KiB
YAML
Raw Normal View History

2021-12-01 13:54:02 +00:00
name: Demo Reset
2021-12-01 11:43:50 +00:00
# Controls when the workflow will run
on:
2021-12-01 13:54:02 +00:00
schedule:
- cron: "0 * * * *"
2021-12-01 11:43:50 +00:00
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# OLD_INSTANCE_SNAPSHOT_NAME=$(aws lightsail get-instance-snapshots | grep '"name": "CasaOS-Demo-Snapshot-[0-9]' | sed 's/ //g' | sed 's/"//g' | sed 's/,//g' | sed 's/name://g')
# OLD_INSTANCE_NAME=$(aws lightsail get-instances | grep '"name": "CasaOS-Demo-[0-9]' | sed 's/ //g' | sed 's/"//g' | sed 's/,//g' | sed 's/name://g')
# NEW_INSTANCE_NAME=CasaOS-Demo-$(date +%s)
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
reset:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Configure AWS credentials from Test account
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
2021-12-01 13:14:34 +00:00
aws-region: us-west-2
2021-12-01 11:43:50 +00:00
2021-12-01 13:05:52 +00:00
- name: Get old instance and snapshot name, create new instance name
2021-12-01 11:43:50 +00:00
run: |
2021-12-01 12:07:44 +00:00
echo "OLD_INSTANCE_SNAPSHOT_NAME=$(aws lightsail get-instance-snapshots | grep '"name": "CasaOS-Demo-Snapshot-[0-9]' | sed 's/ //g' | sed 's/"//g' | sed 's/,//g' | sed 's/name://g')" >> $GITHUB_ENV
echo "OLD_INSTANCE_NAME=$(aws lightsail get-instances | grep '"name": "CasaOS-Demo-[0-9]' | sed 's/ //g' | sed 's/"//g' | sed 's/,//g' | sed 's/name://g')" >> $GITHUB_ENV
2021-12-01 13:05:52 +00:00
echo "NEW_INSTANCE_NAME=CasaOS-Demo-$(date +%s)" >> $GITHUB_ENV
2021-12-01 13:09:18 +00:00
2021-12-01 13:01:40 +00:00
- name: Create instances from snapshot
2021-12-01 11:43:50 +00:00
run: |
aws lightsail create-instances-from-snapshot \
2021-12-01 12:11:32 +00:00
--instance-snapshot-name ${{ env.OLD_INSTANCE_SNAPSHOT_NAME }} \
--instance-names ${{ env.NEW_INSTANCE_NAME }} \
2021-12-01 11:43:50 +00:00
--availability-zone us-west-2a \
--bundle-id large_2_0
2021-12-01 13:01:40 +00:00
- name: Wait for new instance running
2021-12-01 13:46:34 +00:00
run: |
TIMEOUT=$(($(date +%s)+600))
while [ $TIMEOUT -gt $(date +%s) ]
do
2021-12-01 13:49:23 +00:00
NEW_INSTANCE_STATE=$(aws lightsail get-instance-state --instance-name ${{ env.NEW_INSTANCE_NAME }} | grep '"name":' | sed 's/ //g' | sed 's/"//g' | sed 's/name://g')
2021-12-01 13:46:34 +00:00
if [ $NEW_INSTANCE_STATE == running ]
then
echo "New instance is running now"
2021-12-01 13:58:57 +00:00
sleep 10s
2021-12-01 13:46:34 +00:00
break
fi
done
2021-12-01 11:43:50 +00:00
- name: Put instance public ports
run: |
aws lightsail put-instance-public-ports \
--port-infos fromPort=0,toPort=65535,protocol=all \
2021-12-01 12:11:32 +00:00
--instance-name ${{ env.NEW_INSTANCE_NAME }}
2021-12-01 11:43:50 +00:00
- name: Attach static ip
run: |
aws lightsail attach-static-ip \
--static-ip-name CasaOS-Demo-IP \
2021-12-01 12:11:32 +00:00
--instance-name ${{ env.NEW_INSTANCE_NAME }}
2021-12-01 11:43:50 +00:00
- name: Delete old instance
run: |
aws lightsail delete-instance \
2021-12-01 12:11:32 +00:00
--instance-name ${{ env.OLD_INSTANCE_NAME }}
2021-12-01 11:43:50 +00:00