From 3b914abf7a23d4221e4bb1bb46a7681df3a3a445 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 25 Aug 2023 12:46:08 +1000 Subject: [PATCH 01/13] bot: Send a dm with the site info when the site is ready --- discord-bot/bot.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/discord-bot/bot.py b/discord-bot/bot.py index b7969a9..ce9d578 100644 --- a/discord-bot/bot.py +++ b/discord-bot/bot.py @@ -3,6 +3,7 @@ from dotenv import load_dotenv import discord from discord import app_commands import requests +import asyncio load_dotenv() TOKEN = os.getenv('DISCORD_TOKEN') @@ -69,7 +70,24 @@ async def createsite(ctx, domain: str, licence: str): if r.status_code == 200: json = r.json() if json['success'] == "true": - await ctx.response.send_message(f"Site {domain} creating...\nPlease wait a few minutes and then send /siteinfo domain:{domain}") + await ctx.response.send_message(f"Site {domain} creating...\nI'll send you a message when it's ready") + # Set a timer to check if the site is ready + # Keep checking every 30 seconds until it is ready + + ready = False + while ready == False: + ready = await check_site_ready(domain,ctx.user.id) + if ready == False: + await asyncio.sleep(30) + + r = requests.get(f"http://{Master_IP}:{Master_Port}/site-info?domain={domain}") + json = r.json() + if json['success'] == "true": + await ctx.user.send(f"Site {domain} is ready!\nHere is the site info for {json['domain']}\nA: `{json['ip']}`\nTLSA: `{json['tlsa']}`\nMake sure you put the TLSA in either `_443._tcp.{domain}` or `*.{domain}`") + else: + await ctx.user.send(f"Error getting site info\n" + json['error']) + + else: await ctx.response.send_message(f"Error creating site\n" + json['error']) else: @@ -88,6 +106,17 @@ async def siteinfo(ctx, domain: str): else: await ctx.response.send_message(f"Error getting site info\n" + r.text) +async def check_site_ready(domain): + r = requests.get(f"http://{Master_IP}:{Master_Port}/site-info?domain={domain}") + if r.status_code == 200: + json = r.json() + if json['success'] == "true": + return True + else: + return False + else: + return False + # When the bot is ready @client.event async def on_ready(): From ce8827ed97a334c99974a8e379a2c870db068b0f Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 25 Aug 2023 12:49:29 +1000 Subject: [PATCH 02/13] worker: Install missing update repo --- worker/install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/worker/install.sh b/worker/install.sh index 7a1a95b..04ca556 100644 --- a/worker/install.sh +++ b/worker/install.sh @@ -11,6 +11,7 @@ KERNEL_VERSION=$(uname -r) sudo apt-mark hold linux-image-generic linux-headers-generic linux-generic linux-image-$KERNEL_VERSION linux-headers-$KERNEL_VERSION # Install Docker +sudo apt update sudo apt install apt-transport-https ca-certificates curl software-properties-common python3-pip nginx -y curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null From d217309e74e01cc2d015e3e062514abe34f5a2f5 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 25 Aug 2023 12:51:58 +1000 Subject: [PATCH 03/13] bot: Fixed check if site ready function args --- discord-bot/bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord-bot/bot.py b/discord-bot/bot.py index ce9d578..3413083 100644 --- a/discord-bot/bot.py +++ b/discord-bot/bot.py @@ -76,7 +76,7 @@ async def createsite(ctx, domain: str, licence: str): ready = False while ready == False: - ready = await check_site_ready(domain,ctx.user.id) + ready = await check_site_ready(domain) if ready == False: await asyncio.sleep(30) From 908a4e0422a0c97da4efebc1c143cd546ee77735 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 25 Aug 2023 12:54:31 +1000 Subject: [PATCH 04/13] bot: Check for install every 5 seconds --- discord-bot/bot.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/discord-bot/bot.py b/discord-bot/bot.py index 3413083..0450dbc 100644 --- a/discord-bot/bot.py +++ b/discord-bot/bot.py @@ -71,14 +71,12 @@ async def createsite(ctx, domain: str, licence: str): json = r.json() if json['success'] == "true": await ctx.response.send_message(f"Site {domain} creating...\nI'll send you a message when it's ready") - # Set a timer to check if the site is ready - # Keep checking every 30 seconds until it is ready ready = False while ready == False: ready = await check_site_ready(domain) if ready == False: - await asyncio.sleep(30) + await asyncio.sleep(5) r = requests.get(f"http://{Master_IP}:{Master_Port}/site-info?domain={domain}") json = r.json() From 778c1b3d9210114219718c353d7e85c66942022a Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 25 Aug 2023 13:21:24 +1000 Subject: [PATCH 05/13] actions: Change numbering --- .gitea/workflows/build.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 6127c18..756435e 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -21,10 +21,11 @@ jobs: run : | cd master echo "${{ secrets.DOCKERGIT_TOKEN }}" | docker login git.woodburn.au -u nathanwoodburn --password-stdin - tag_num=$(git rev-parse --short HEAD) echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" tag=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} tag=${tag//\//-} + tag_num=$(git rev-list --count HEAD) + if [[ "$tag" == "main" ]]; then tag="latest" else @@ -60,10 +61,10 @@ jobs: run : | cd discord-bot echo "${{ secrets.DOCKERGIT_TOKEN }}" | docker login git.woodburn.au -u nathanwoodburn --password-stdin - tag_num=$(git rev-parse --short HEAD) echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" tag=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} tag=${tag//\//-} + tag_num=$(git rev-list --count HEAD) if [[ "$tag" == "main" ]]; then tag="latest" else From 45c1ea35574daac4c9c5015d606eaba5334484ba Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 25 Aug 2023 13:25:00 +1000 Subject: [PATCH 06/13] actions: Test 2 change numbering --- .gitea/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 756435e..a01c675 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -25,6 +25,9 @@ jobs: tag=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} tag=${tag//\//-} tag_num=$(git rev-list --count HEAD) + echo "tag_num=$tag_num" + + tag_num=$(git rev-list ${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} --count) if [[ "$tag" == "main" ]]; then tag="latest" From 04edb8b456b544b54f3b71ec4c0d58f7086a0162 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 25 Aug 2023 13:26:41 +1000 Subject: [PATCH 07/13] actions: Test 3 change numbering --- .gitea/workflows/build.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index a01c675..77d2cff 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -24,10 +24,8 @@ jobs: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" tag=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} tag=${tag//\//-} - tag_num=$(git rev-list --count HEAD) - echo "tag_num=$tag_num" - - tag_num=$(git rev-list ${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} --count) + tag_num=${git log --oneline | wc -l} + echo "tag_num=$tag_num" if [[ "$tag" == "main" ]]; then tag="latest" From 3e3c2fe61eb404c97a637ab5d00df9637620d636 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 25 Aug 2023 13:28:06 +1000 Subject: [PATCH 08/13] actions: Test 4 change numbering --- .gitea/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 77d2cff..b68e1fe 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -24,7 +24,7 @@ jobs: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" tag=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} tag=${tag//\//-} - tag_num=${git log --oneline | wc -l} + tag_num=$(git log --oneline | wc -l) echo "tag_num=$tag_num" if [[ "$tag" == "main" ]]; then From b642cf726967529911b1e12b37d3bbf576c72b8d Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 25 Aug 2023 13:37:24 +1000 Subject: [PATCH 09/13] actions: Try using the actions run variable --- .gitea/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index b68e1fe..e46c248 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -24,7 +24,7 @@ jobs: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" tag=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} tag=${tag//\//-} - tag_num=$(git log --oneline | wc -l) + tag_num=${GITHUB_RUN_NUMBER} echo "tag_num=$tag_num" if [[ "$tag" == "main" ]]; then From b38de6ad52bc9c289097398a84a6a1b0e7fbd89e Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 25 Aug 2023 13:39:26 +1000 Subject: [PATCH 10/13] actions: Use same numbering on bot deployment --- .gitea/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index e46c248..f15fd17 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -65,7 +65,7 @@ jobs: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" tag=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} tag=${tag//\//-} - tag_num=$(git rev-list --count HEAD) + tag_num=${GITHUB_RUN_NUMBER} if [[ "$tag" == "main" ]]; then tag="latest" else From 51bcdda5d45a7ce77a961a586ecef0da2416a262 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 25 Aug 2023 13:44:13 +1000 Subject: [PATCH 11/13] actions: Initial release job --- .gitea/workflows/build.yml | 3 +-- .gitea/workflows/release.yml | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 .gitea/workflows/release.yml diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index f15fd17..5c30eba 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -76,5 +76,4 @@ jobs: docker tag hnshosting-bot:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-bot:$tag_num docker push git.woodburn.au/nathanwoodburn/hnshosting-bot:$tag_num docker tag hnshosting-bot:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-bot:$tag - docker push git.woodburn.au/nathanwoodburn/hnshosting-bot:$tag - \ No newline at end of file + docker push git.woodburn.au/nathanwoodburn/hnshosting-bot:$tag \ No newline at end of file diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..5dd42ae --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,16 @@ +name: Build Docker for Release +run-name: Build Docker Images + +on: + push: + tags: + - '*' + +jobs: + TEST: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Print tag + run: echo "tag=${GITHUB_REF#refs/tags/}" \ No newline at end of file From 4841344d63e3e168378bc4ec0f8d66b039aa98f2 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 25 Aug 2023 13:48:39 +1000 Subject: [PATCH 12/13] actions: Finished adding release --- .gitea/workflows/release.yml | 55 +++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 5dd42ae..ce4c7e5 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -6,11 +6,58 @@ on: tags: - '*' -jobs: - TEST: +Build Master: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 - - name: Print tag - run: echo "tag=${GITHUB_REF#refs/tags/}" \ No newline at end of file + - name: Install Docker + run : | + apt-get install ca-certificates curl gnupg + install -m 0755 -d /etc/apt/keyrings + curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg + chmod a+r /etc/apt/keyrings/docker.gpg + echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null + apt-get update + apt-get install docker-ce-cli -y + - name: Build Docker image + run : | + cd master + echo "${{ secrets.DOCKERGIT_TOKEN }}" | docker login git.woodburn.au -u nathanwoodburn --password-stdin + tag=${GITHUB_REF#refs/tags/} + + docker build -t hnshosting-master:release-$tag . + docker tag hnshosting-master:release-$tag git.woodburn.au/nathanwoodburn/hnshosting-master:release-$tag + docker push git.woodburn.au/nathanwoodburn/hnshosting-master:release-$tag + docker tag hnshosting-master:release-$tag git.woodburn.au/nathanwoodburn/hnshosting-master:release + docker push git.woodburn.au/nathanwoodburn/hnshosting-master:release + + + + + + Build Bot: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Install Docker + run : | + apt-get install ca-certificates curl gnupg + install -m 0755 -d /etc/apt/keyrings + curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg + chmod a+r /etc/apt/keyrings/docker.gpg + echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null + apt-get update + apt-get install docker-ce-cli -y + - name: Build Docker image + run : | + cd discord-bot + echo "${{ secrets.DOCKERGIT_TOKEN }}" | docker login git.woodburn.au -u nathanwoodburn --password-stdin + tag=${GITHUB_REF#refs/tags/} + + docker build -t hnshosting-bot:release-$tag . + docker tag hnshosting-bot:release-$tag git.woodburn.au/nathanwoodburn/hnshosting-bot:release-$tag + docker push git.woodburn.au/nathanwoodburn/hnshosting-bot:release-$tag + docker tag hnshosting-bot:release-$tag git.woodburn.au/nathanwoodburn/hnshosting-bot:release + docker push git.woodburn.au/nathanwoodburn/hnshosting-bot:release \ No newline at end of file From ed942630506a4fb88bd73e910abe32ae3cbb7e52 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 25 Aug 2023 13:53:28 +1000 Subject: [PATCH 13/13] actions: Don't run dev action when tag is pushed --- .gitea/workflows/build.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 5c30eba..c09eabc 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -1,6 +1,11 @@ name: Build Docker run-name: Build Docker Images -on: [push] +on: + push: + branches: + - '*' + tags-ignore: + - '*' jobs: Build Master: