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
|
2023-03-22 02:59:31 +00:00
|
|
|
- uses: actions/checkout@v3
|
2021-12-01 11:43:50 +00:00
|
|
|
|
|
|
|
- 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: |
|
2023-06-25 09:07:17 +00:00
|
|
|
echo "OLD_INSTANCE_SNAPSHOT_NAME=updateto_to_0.4.4-1684926517" >> $GITHUB_ENV
|
2023-06-25 09:09:31 +00:00
|
|
|
echo "OLD_INSTANCE_NAME=$(aws lightsail get-instances | grep '"name": "CasaOS-Demo-[0-9]' | tail -1 | sed 's/ //g' | sed 's/"//g' | sed 's/,//g' | sed 's/name://g')" >> $GITHUB_ENV
|
|
|
|
# echo "OLD_INSTANCE_NAME=CasaOS-Demo-1687680295" >> $GITHUB_ENV
|
2023-05-06 03:35:44 +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 \
|
2022-05-18 08:58:33 +00:00
|
|
|
--bundle-id medium_2_0
|
2021-12-01 11:43:50 +00:00
|
|
|
|
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 }}
|
2023-06-07 08:09:01 +00:00
|
|
|
- name: Demo Reset Error Handling
|
|
|
|
if: ${{ failure() }}
|
|
|
|
run: |
|
|
|
|
curl -X POST -H "Content-Type: application/json" -d '{"msg_type":"text","content":{"text":"Demo Reset Error"}}' ${{ secrets.SSH_ROBOT_URL }}
|
2021-12-01 11:43:50 +00:00
|
|
|
|
|
|
|
|