From ba7e1ca1897170de27718ee6723b79ae6a2c0a5c Mon Sep 17 00:00:00 2001 From: Thomas Marchand Date: Tue, 9 Apr 2024 16:06:04 +0100 Subject: [PATCH] feat: add auto testnet deployment workflow --- .github/workflows/testnet_deploy.yml | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/testnet_deploy.yml diff --git a/.github/workflows/testnet_deploy.yml b/.github/workflows/testnet_deploy.yml new file mode 100644 index 0000000..30997cc --- /dev/null +++ b/.github/workflows/testnet_deploy.yml @@ -0,0 +1,53 @@ +name: Testnet deployment + +on: + push: + branches: + - testnet + +jobs: + deploy: + runs-on: ubuntu-latest + env: + SSH_HOST: sepolia.api.starknet.id + SSH_USER: ubuntu + REPO_PATH: '~/api.starknet.id' + AWS_PATH: 'lfg-labs/api.starknet.id/sepolia' + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: 'eu-west-3' + steps: + - name: Setting up SSH key + uses: webfactory/ssh-agent@v0.5.3 + with: + ssh-private-key: ${{ secrets.SSH_KEY }} + + - name: Remote deployment + run: | + ssh -o StrictHostKeyChecking=no -T $SSH_USER@$SSH_HOST << EOF + export REPO_PATH=$REPO_PATH + + # Configure AWS CLI + aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID + aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY + aws configure set default.region $AWS_DEFAULT_REGION + + if [ -d "\$REPO_PATH/.git" ]; then + echo "Repository exists, pulling changes..." + cd \$REPO_PATH + sudo docker-compose down + git pull + else + echo "Repository doesn't exist, cloning..." + mkdir -p \$REPO_PATH + git clone git@github.com:starknet-id/api.starknet.id.git \$REPO_PATH + cd \$REPO_PATH + fi + + # Use AWS CLI to copy configuration files from S3 + sudo chown -R \$SSH_USER:\$SSH_USER \$REPO_PATH + sudo chmod -R 755 \$REPO_PATH + aws s3 cp s3://$AWS_PATH/ \$REPO_PATH --recursive + + sudo docker-compose up --build -d + EOF