diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index c2a130f35..b79a0a2b3 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -9,7 +9,7 @@ on: jobs: deploy-staging: name: Deploy Staging - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 if: github.ref_name == 'main' || github.ref_name == 'develop' || startsWith(github.ref_name, 'feature/') steps: @@ -19,10 +19,30 @@ jobs: GITHUB_TOKEN: ${{ github.token }} run: | set -eu - archive_url="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/archive/${GITHUB_SHA}.tar.gz" - wget --header="Authorization: token ${GITHUB_TOKEN}" -O /tmp/repo.tar.gz "$archive_url" - tar -xzf /tmp/repo.tar.gz --strip-components=1 -C . - rm -f /tmp/repo.tar.gz + python3 - <<'PY' + import io, os, tarfile, urllib.request + url = f"{os.environ['GITHUB_API_URL']}/repos/{os.environ['GITHUB_REPOSITORY']}/archive/{os.environ['GITHUB_SHA']}.tar.gz" + request = urllib.request.Request(url, headers={"Authorization": f"token {os.environ['GITHUB_TOKEN']}"}) + with urllib.request.urlopen(request, timeout=120) as response: + archive = response.read() + with tarfile.open(fileobj=io.BytesIO(archive), mode='r:gz') as tar: + root_prefix = tar.getmembers()[0].name.split('/', 1)[0] + '/' + for member in tar.getmembers(): + name = member.name + if name == root_prefix[:-1]: + continue + if name.startswith(root_prefix): + member.name = name[len(root_prefix):] + if member.name: + tar.extract(member, '.') + PY + + - name: Install SSH client + shell: sh + run: | + set -eu + apt-get update -qq && apt-get install -y -qq openssh-client >/dev/null 2>&1 + echo "openssh-client installed" - name: Build staging web artifact shell: sh @@ -95,7 +115,7 @@ jobs: build-production-runtime-images: name: Build Production Runtime Images - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 if: startsWith(github.ref, 'refs/tags/v') steps: @@ -105,10 +125,23 @@ jobs: GITHUB_TOKEN: ${{ github.token }} run: | set -eu - archive_url="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/archive/${GITHUB_SHA}.tar.gz" - wget --header="Authorization: token ${GITHUB_TOKEN}" -O /tmp/repo.tar.gz "$archive_url" - tar -xzf /tmp/repo.tar.gz --strip-components=1 -C . - rm -f /tmp/repo.tar.gz + python3 - <<'PY' + import io, os, tarfile, urllib.request + url = f"{os.environ['GITHUB_API_URL']}/repos/{os.environ['GITHUB_REPOSITORY']}/archive/{os.environ['GITHUB_SHA']}.tar.gz" + request = urllib.request.Request(url, headers={"Authorization": f"token {os.environ['GITHUB_TOKEN']}"}) + with urllib.request.urlopen(request, timeout=120) as response: + archive = response.read() + with tarfile.open(fileobj=io.BytesIO(archive), mode='r:gz') as tar: + root_prefix = tar.getmembers()[0].name.split('/', 1)[0] + '/' + for member in tar.getmembers(): + name = member.name + if name == root_prefix[:-1]: + continue + if name.startswith(root_prefix): + member.name = name[len(root_prefix):] + if member.name: + tar.extract(member, '.') + PY - name: Build runtime image artifact shell: sh @@ -186,11 +219,18 @@ jobs: deploy-production: name: Deploy Production - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 if: startsWith(github.ref, 'refs/tags/v') needs: build-production-runtime-images steps: + - name: Install SSH client + shell: sh + run: | + set -eu + apt-get update -qq && apt-get install -y -qq openssh-client >/dev/null 2>&1 + echo "openssh-client installed" + - name: Deploy production over SSH shell: sh env: @@ -215,7 +255,7 @@ jobs: production-e2e: name: Production Browser E2E - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 if: startsWith(github.ref, 'refs/tags/v') needs: deploy-production @@ -226,10 +266,23 @@ jobs: GITHUB_TOKEN: ${{ github.token }} run: | set -eu - archive_url="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/archive/${GITHUB_SHA}.tar.gz" - wget --header="Authorization: token ${GITHUB_TOKEN}" -O /tmp/repo.tar.gz "$archive_url" - tar -xzf /tmp/repo.tar.gz --strip-components=1 -C . - rm -f /tmp/repo.tar.gz + python3 - <<'PY' + import io, os, tarfile, urllib.request + url = f"{os.environ['GITHUB_API_URL']}/repos/{os.environ['GITHUB_REPOSITORY']}/archive/{os.environ['GITHUB_SHA']}.tar.gz" + request = urllib.request.Request(url, headers={"Authorization": f"token {os.environ['GITHUB_TOKEN']}"}) + with urllib.request.urlopen(request, timeout=120) as response: + archive = response.read() + with tarfile.open(fileobj=io.BytesIO(archive), mode='r:gz') as tar: + root_prefix = tar.getmembers()[0].name.split('/', 1)[0] + '/' + for member in tar.getmembers(): + name = member.name + if name == root_prefix[:-1]: + continue + if name.startswith(root_prefix): + member.name = name[len(root_prefix):] + if member.name: + tar.extract(member, '.') + PY - name: Run production browser E2E shell: sh