Skip to content

Commit

Permalink
ci(e2e): set exact commit sha to use for e2e images (#1149)
Browse files Browse the repository at this point in the history
* ci(e2e): set exact commit sha to use for e2e images

Resolves #1146

* We should also wait for the exact sha workflow

* fix(ci): I used the wrong workflow here 2 weeks ago

* feat(dev): add `--verbose` flag to deploy.py to print commands that are executed in shell

* feat(ci): enable command logging for deploy.py in ci
  • Loading branch information
corneliusroemer committed Feb 26, 2024
1 parent 0983cac commit fdc00dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/e2e-k3d.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- "kubernetes/**"
- "preprocessing/**"
- "deploy.py"
- ".github/workflows/e2e-test.yml"
- ".github/workflows/e2e-k3d.yml"

concurrency:
group: ci-${{ github.ref == 'refs/heads/main' && github.run_id || github.ref }}-e2e-k3d
Expand All @@ -34,7 +34,7 @@ jobs:
- name: Create k3d cluster
run: |
./deploy.py cluster
./deploy.py --verbose cluster
- name: Test helm template
uses: WyriHaximus/github-action-helm3@v4
Expand Down Expand Up @@ -82,21 +82,21 @@ jobs:
- name: Wait for Backend Docker Image
uses: lewagon/wait-on-check-action@v1.3.3
with:
ref: ${{ github.ref }}
ref: ${{ github.sha }}
check-name: Build Backend Docker Image
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Wait for Website Docker Image
uses: lewagon/wait-on-check-action@v1.3.3
with:
ref: ${{ github.ref }}
ref: ${{ github.sha }}
check-name: Build Website Docker Image
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Deploy with helm
uses: WyriHaximus/github-action-helm3@v4
with:
exec: ./deploy.py helm --branch ${{ github.ref_name }} --dockerconfigjson ${{ secrets.GHCR_DOCKER_CONFIG }}
exec: ./deploy.py --verbose helm --branch ${{ github.ref_name }} --sha ${{ github.sha }} --dockerconfigjson ${{ secrets.GHCR_DOCKER_CONFIG }}

- name: Wait for the pods to be ready
run: ./.github/scripts/wait_for_pods_to_be_ready.py
Expand Down
11 changes: 9 additions & 2 deletions deploy.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python3

import argparse
import os
import subprocess
import time
from pathlib import Path
import os

import yaml

script_path = Path(__file__).resolve()
Expand All @@ -28,6 +29,7 @@
parser = argparse.ArgumentParser(description='Manage k3d cluster and helm installations.')
subparsers = parser.add_subparsers(dest='subcommand', required=True, help='Subcommands')
parser.add_argument('--dry-run', action='store_true', help='Print commands instead of executing them')
parser.add_argument('--verbose', action='store_true', help='Print commands that are executed')

cluster_parser = subparsers.add_parser('cluster', help='Start the k3d cluster')
cluster_parser.add_argument('--dev', action='store_true',
Expand All @@ -38,6 +40,7 @@
helm_parser.add_argument('--dev', action='store_true',
help='Set up a development environment for running the website and the backend locally')
helm_parser.add_argument('--branch', help='Set the branch to deploy with the Helm chart')
helm_parser.add_argument('--sha', help='Set the commit sha to deploy with the Helm chart')
helm_parser.add_argument('--dockerconfigjson',
help='Set the base64 encoded dockerconfigjson secret for pulling the images')
helm_parser.add_argument('--uninstall', action='store_true', help='Uninstall installation')
Expand All @@ -53,11 +56,12 @@
args = parser.parse_args()

def run_command(command: list[str], **kwargs):
if args.dry_run:
if args.dry_run or args.verbose:
if isinstance(command, str):
print(command)
else:
print(" ".join(map(str,command)))
if args.dry_run:
return subprocess.CompletedProcess(args=command, returncode=0, stdout="", stderr="")
else:
return subprocess.run(command, **kwargs)
Expand Down Expand Up @@ -141,6 +145,9 @@ def handle_helm():
'--set', f"dockerconfigjson={docker_config_json}",
]

if args.sha:
parameters += ['--set', f"sha={args.sha[:7]}"]

if args.dev:
parameters += ['--set', "disableBackend=true"]
parameters += ['--set', "disableWebsite=true"]
Expand Down

0 comments on commit fdc00dd

Please sign in to comment.