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

Fix wiab automation #742

Merged
merged 20 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
7 changes: 6 additions & 1 deletion .github/workflows/custom-artifact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
workflow_dispatch:
jobs:
offline:
name: Prepare custom offline package
name: Prepare custom offline package # Do not change this name, it is used to trigger deploy-wiab workflow
# Useful to skip expensive CI when writing docs
if: "!contains(github.event.head_commit.message, 'skip ci')"
runs-on:
Expand Down Expand Up @@ -54,6 +54,11 @@ jobs:
env:
DOCKER_LOGIN: '${{ secrets.DOCKER_LOGIN }}'

# Set output for deploy-wiab workflow to start
- name: Set output to trigger dependent workflow
if: success()
run: echo "::set-output name=trigger_next_workflow::true"

- name: Deploy offline environment to hetzner
run: |
./offline/cd.sh
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/deploy-wiab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Deploy on Hetnzer WIAB setup
amitsagtani97 marked this conversation as resolved.
Show resolved Hide resolved
on:
pull_request:
branches:
- master
workflow_run:
workflows: ["Prepare custom offline package"]
types:
- completed

jobs:
deploy:
runs-on: ubuntu-latest
concurrency:
group: autodeploy-script
cancel-in-progress: false

steps:
# Step 1: Checkout the repository code
- name: Checkout code
uses: actions/checkout@v3

# Step 2: Set up SSH key for remote access
- name: Set up SSH key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.WIAB_PRIVATE_SSH_KEY }}

# Step 3: Get the latest commit SHA, for the artifact
- name: Get latest commit SHA
id: get_commit_sha
run: |
COMMIT_SHA=$(git rev-parse --short HEAD)
echo "commit_sha=$COMMIT_SHA" >> $GITHUB_ENV

# Step 4: Run the autodeploy script
- name: Run Auto Deploy Script
run: |
cd bin
./autodeploy.sh --artifact-hash ${{ env.commit_sha }} --target-domain wiab-test-box.wire.link --force-redeploy
2 changes: 1 addition & 1 deletion ansible/hetzner-single-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
become: true
vars:
artifact_hash: d8fe36747614968ea73ebd43d47b99364c52f9c1
ubuntu_version: 22.04.4
ubuntu_version: 22.04.5
ssh_pubkey: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDPTGTo1lTqd3Ym/75MRyQvj8xZINO/GI6FzfIadSe5c [email protected]"
tasks:
- name: set ipv4 forward
Expand Down
30 changes: 21 additions & 9 deletions bin/autodeploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ msg ""
msg "INFO: starting Wire-in-a-box deployment for $TARGET_SYSTEM using artifact ID $ARTIFACT_HASH"
msg ""


for SUBDOMAIN in $SUBDOMAINS; do
if host "$SUBDOMAIN"."$TARGET_SYSTEM" >/dev/null 2>&1 ; then
msg "INFO: DNS A record exists: $SUBDOMAIN.$TARGET_SYSTEM"
Expand All @@ -107,6 +108,7 @@ else
die "ERROR: Can't log into $TARGET_SYSTEM via SSH, please check SSH connectivity."
fi


if curl --head --silent --fail https://s3-eu-west-1.amazonaws.com/public.wire.com/artifacts/wire-server-deploy-static-"$ARTIFACT_HASH".tgz >/dev/null 2>&1 ; then
msg "INFO: Artifact exists https://s3-eu-west-1.amazonaws.com/public.wire.com/artifacts/wire-server-deploy-static-$ARTIFACT_HASH.tgz"
else
Expand All @@ -127,8 +129,12 @@ EOT
}

system_cleanup() {
for VM in $(virsh list --all --name); do virsh destroy "$VM"; virsh undefine "$VM" --remove-all-storage; done
docker system prune -a -f
if which virsh > /dev/null; then
for VM in $(virsh list --all --name); do virsh destroy "$VM"; virsh undefine "$VM" --remove-all-storage; done
fi
if which docker > /dev/null; then
docker system prune -a -f
fi
rm -f /home/$DEMO_USER/.ssh/known_hosts
rm -rf /home/$DEMO_USER/wire-server-deploy
rm -f /home/$DEMO_USER/wire-server-deploy-static-*.tgz
Expand All @@ -139,7 +145,12 @@ preprovision_hetzner() {
msg "INFO: running local ansible playbook for inital server deployment."
msg "INFO: This will setup up the Hetzner system with basic defaults, download and unpack the wire-server-deploy artifact."
sleep 5
export LC_ALL="C.UTF-8";
# on Mac devices C.UTF-8 is not available
if [[ $(uname) == "Darwin" ]]; then
export LC_ALL=en_US.UTF-8
else
export LC_ALL=C.UTF-8
fi
ansible-playbook ../ansible/hetzner-single-deploy.yml -e "artifact_hash=$ARTIFACT_HASH" -i $SSH_USER@webapp."$TARGET_SYSTEM", --diff
}

Expand Down Expand Up @@ -367,21 +378,22 @@ EOF
d helm upgrade --install coturn ./charts/coturn --values values/coturn/values.yaml --values values/coturn/secrets.yaml
}

EXISTING_INSTALL=$(ssh -p "$SSH_PORT" "$SSH_USER"@webapp."$TARGET_SYSTEM" "ls /home/$DEMO_USER/wire-server-deploy-static-*.tgz 2>/dev/null" || true)
EXISTING_VMS=$(ssh -p "$SSH_PORT" "$SSH_USER"@webapp."$TARGET_SYSTEM" "virsh list --all --name")
EXISTING_CONTAINERS=$(ssh -p "$SSH_PORT" "$SSH_USER"@webapp."$TARGET_SYSTEM" "docker ps -q --all")
EXISTING_INSTALL=$(ssh -p "$SSH_PORT" "$SSH_USER"@webapp."$TARGET_SYSTEM" "ls /home/$DEMO_USER/wire-server-deploy-static-*.tgz 2>/dev/null" || echo "false")
EXISTING_VMS=$(ssh -p "$SSH_PORT" "$SSH_USER"@webapp."$TARGET_SYSTEM" "virsh list --all --name" || echo "false")
EXISTING_CONTAINERS=$(ssh -p "$SSH_PORT" "$SSH_USER"@webapp."$TARGET_SYSTEM" "docker ps -q --all" || echo "false")

if [[ "$EXISTING_INSTALL" ]]; then
if [[ "$EXISTING_INSTALL" != "false" && -n "$EXISTING_INSTALL" ]]; then
msg ""
msg "WARNING: existing wire-server-deploy installation found: $EXISTING_INSTALL"
DO_SYSTEM_CLEANUP=true
fi
if [[ "$EXISTING_VMS" ]]; then
if [[ "$EXISTING_VMS" != "false" && -n "$EXISTING_VMS" ]]; then
msg ""
msg "WARNING: existing libvirt VMs found: $EXISTING_VMS"
DO_SYSTEM_CLEANUP=true
fi
if [[ "$EXISTING_CONTAINERS" ]]; then
if [[ "$EXISTING_CONTAINERS" != "false" && -n "$EXISTING_CONTAINERS" ]]; then
echo "$EXISTING_CONTAINERS"
msg ""
msg "WARNING: existing Docker containers found."
DO_SYSTEM_CLEANUP=true
Expand Down
Loading