Skip to content

Deploy by @mesudip #137

Deploy by @mesudip

Deploy by @mesudip #137

name: Build and deploy GovTool test stack
run-name: Deploy by @${{ github.actor }}
on:
push:
branches:
- test
- infra/test-chores
env:
ENVIRONMENT: "test"
CARDANO_NETWORK: "sanchonet"
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up SSH and deploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.TEST_STACK_SERVER_IP }}
username: ec2-user
key: ${{ secrets.TEST_STACK_SSH_KEY }}
command_timeout: 100m ## Haskell container build takes a lot of time.
script: |
set -euo pipefail
REPO_URL="https://github.com/${{ github.repository }}"
DEST_DIR="$HOME/Documents/govtool"
# Create parent directory if it does not exist
mkdir -p "$(dirname "$DEST_DIR")"
# Check if $DEST_DIR exists
if [ -d "$DEST_DIR" ]; then
if [ -d "$DEST_DIR/.git" ]; then
cd $DEST_DIR || exit
echo "Updating repository..."
git fetch --all
git checkout --force "${{ github.sha }}"
else
echo "Not a git repository. Re-cloning..."
rm -rf "$DEST_DIR"
git clone "$REPO_URL" "$DEST_DIR"
cd "$DEST_DIR" || exit
git checkout --force "${{ github.sha }}"
fi
else
echo "Directory does not exist. Cloning repository..."
git clone "$REPO_URL" "$DEST_DIR"
cd "$DEST_DIR" || exit
git checkout --force "${{ github.sha }}"
fi
cd $DEST_DIR/tests/test-infrastructure
# Create a backup of the .env file if it exists
ENV_FILE=".env"
if [ -f "$ENV_FILE" ]; then
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")
BACKUP_FILE="${ENV_FILE}_backup_$TIMESTAMP"
echo "Backing up existing .env file to $BACKUP_FILE..."
cp "$ENV_FILE" "$BACKUP_FILE"
fi
echo "Writing environment variables to .env file..."
cat <<EOF > "$ENV_FILE"
GOVTOOL_TAG=${{ github.sha }}
GRAFANA_ADMIN_PASSWORD=${{ secrets.GRAFANA_ADMIN_PASSWORD }}
GRAFANA_SLACK_RECIPIENT=${{ secrets.GRAFANA_SLACK_RECIPIENT }}
GRAFANA_SLACK_OAUTH_TOKEN=${{ secrets.GRAFANA_SLACK_OAUTH_TOKEN }}
SENTRY_DSN_BACKEND=${{ secrets.SENTRY_DSN_BACKEND }}
GTM_ID=${{ secrets.GTM_ID }}
NPMRC_TOKEN=${{ secrets.NPMRC_TOKEN }}
SENTRY_DSN_FRONTEND=${{ secrets.SENTRY_DSN_FRONTEND }}
PIPELINE_URL=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
USERSNAP_SPACE_API_KEY=${{ secrets.USERSNAP_SPACE_API_KEY }}
APP_ENV=test
PDF_API_URL=${{ secrets.PDF_API_URL }}
KUBER_API_KEY=${{ secrets.KUBER_API_KEY }}
IPFS_GATEWAY=${{ secrets.IPFS_GATEWAY }}
IPFS_PROJECT_ID=${{ secrets.IPFS_PROJECT_ID }}
EOF
# Execute the build-and-deploy.sh script
./build-and-deploy.sh update-images
yes | docker system prune -f || echo "Ignoring system prune error"