Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infra/test chores #1759

Merged
merged 5 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 50 additions & 26 deletions .github/workflows/build-and-deploy-test-stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,63 @@ jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
env:
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}}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup SSH agent
uses: webfactory/ssh-agent@v0.8.0
- name: Set up SSH and deploy
uses: appleboy/ssh-action@v1.0.3
with:
ssh-private-key: ${{ secrets.TEST_STACK_SSH_KEY }}

- name: Run Ansible playbook
uses: dawidd6/action-ansible-playbook@v2
with:
playbook: playbook.yml
directory: ./tests/test-infrastructure
host: ${{ secrets.TEST_STACK_SERVER_IP }}
username: ec2-user
key: ${{ secrets.TEST_STACK_SSH_KEY }}
inventory: |
[test_server]
${{ secrets.TEST_STACK_SERVER_IP }} ansible_user=ec2-user
options: |
--verbose
command_timeout: 100m ## Haskell container build takes a lot of time.
script: |
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 "$GOVTOOL_TAG"
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 "$GOVTOOL_TAG"
fi
else
echo "Directory does not exist. Cloning repository..."
git clone "$REPO_URL" "$DEST_DIR"
cd "$DEST_DIR" || exit
git checkout --force "$GOVTOOL_TAG"
fi

# Execute the build-and-deploy.sh script
cd $DEST_DIR/tests/test-infrastructure
./build-and-deploy.sh update-images
docker system prune
(docker image ls -q | xargs docker image rm --force ) || echo "Images cleaned-up"
envs: GOVTOOL_TAG, GRAFANA_ADMIN_PASSWORD, GRAFANA_SLACK_RECIPIENT, GRAFANA_SLACK_OAUTH_TOKEN, SENTRY_DSN_BACKEND, GTM_ID, NPMRC_TOKEN, SENTRY_DSN_FRONTEND, PIPELINE_URL, USERSNAP_SPACE_API_KEY, APP_ENV, PDF_API_URL
env:
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 }}
1 change: 1 addition & 0 deletions tests/test-infrastructure/build-and-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ check_env
# Build images
./build-images.sh
function update-service(){
echo '> docker' service update --image "$2" "$1"
docker service update --image "$2" "$1"
}

Expand Down
17 changes: 13 additions & 4 deletions tests/test-infrastructure/build-images.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
#!/usr/bin/env bash
set -e

# Define a function to log and execute Docker commands
docker_() {
local cmd="$*"
echo docker "$cmd"
docker $cmd
}

export BASE_IMAGE_NAME="govtool"

BASE_IMAGE_EXISTS=$(docker images -q "$BASE_IMAGE_NAME"/backend-base)

if [ -z "$BASE_IMAGE_EXISTS" ]; then
echo "Building the base image..."
docker build -t "$BASE_IMAGE_NAME"/backend-base -f ../../govtool/backend/Dockerfile.base ../../govtool/backend
docker_ build -t "$BASE_IMAGE_NAME"/backend-base -f ../../govtool/backend/Dockerfile.base ../../govtool/backend
else
echo "Base image already exists. Skipping build."
fi

docker compose -f ./docker-compose-govtool.yml build
docker compose -f ./docker-compose-govaction-loader.yml build
docker compose -f ./docker-compose-test.yml build
docker_ compose -f ./docker-compose-govtool.yml build
docker_ compose -f ./docker-compose-govaction-loader.yml build
docker_ compose -f ./docker-compose-test.yml build
Loading