Skip to content

Commit

Permalink
Merge pull request #281 from kbst/test-refactor-pipeline
Browse files Browse the repository at this point in the history
Stop building pre Terraform module artifacts
  • Loading branch information
pst authored Sep 10, 2023
2 parents 270b347 + 1dc0b2c commit 0ea4488
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 242 deletions.
29 changes: 8 additions & 21 deletions .github/actions/builder/builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@
def create_archive(name, version):
src = join(SRCDIR, name)

# legacy format artifacts
archive_dist = join(DISTDIR, name)
archive = join(DISTDIR, f'{name}-{version}')

copytree(src, archive_dist, ignore=ignore_patterns('_*', '*.tf'))

make_archive(archive, 'zip', DISTDIR, name)
print(f"[INFO] created `{archive}.zip`")

# terraform module artifacts
module_dist = join(DISTDIR, f'module-{name}')
module = join(DISTDIR, f'module-{name}-{version}')

Expand Down Expand Up @@ -47,14 +37,10 @@ def get_build_targets(ref):

if ref.startswith('refs/tags/'):
ref_name = ref.replace('refs/tags/', '')
hash_suffx = False
is_tag = True
elif ref.startswith('refs/heads/'):
ref_name = ref.replace('refs/heads/', '')
hash_suffx = True

hash = environ.get('GITHUB_SHA', None)[0:7]
if not hash:
exit(f"[ERROR] `GITHUB_SHA` env var not set")
is_tag = False

available_names = [n for n in listdir(SRCDIR) if not n.startswith('_')]

Expand All @@ -66,10 +52,11 @@ def get_build_targets(ref):
version = ref_name.replace(prefix, '')

# Version based on branch (e.g. refs/heads/nginx-mychange)
if hash_suffx:

# Append hash to `mychange` from branch name
version = f'{version}-{hash}'
if not is_tag:
hash = environ.get('GITHUB_SHA', None)
if not hash:
exit(f"[ERROR] `GITHUB_SHA` env var not set")
version = hash

if ref_name.startswith(prefix):
# We're building a specific target
Expand All @@ -89,7 +76,7 @@ def get_build_targets(ref):

# if neither a specifc nor all entries were requested
# we default to the test entry
return [("test", f"{ref_name}-{hash}")]
return [("test", hash)]


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/updater/updater/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def update_entry(self, entry):
# checkout tag to build in source repo
entry.repo.git.checkout('-f', entry.tag)

self.branch_name = f'{release_tag}'
self.branch_name = f'release-{release_tag}'
self.repo.git.checkout(settings.CATALOG_REF)
self.repo.git.clean('-xdf')
self.repo.git.checkout('-B', self.branch_name)
Expand Down
79 changes: 12 additions & 67 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ on:
branches:
- "*" # run for branches
tags:
- "*" # run for tags
- "!*" # do not run for tags

env:
TERRAFORM_VERSION: "1.3.4"
TERRAFORM_VERSION: "1.5.7"

jobs:


#
#
# Build artifacts
Expand All @@ -36,7 +34,7 @@ jobs:

#
#
# Test `kustomize build`
# Run `terraform test`
test-terraform:
runs-on: ubuntu-latest

Expand All @@ -46,7 +44,7 @@ jobs:

# Setup Terraform
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1.3.2
uses: hashicorp/setup-terraform@v2.0.3
with:
terraform_wrapper: false
terraform_version: "${{ env.TERRAFORM_VERSION }}"
Expand All @@ -56,38 +54,6 @@ jobs:
run: make test-terraform


#
#
# Test `kustomize build`
test-kustomize:
runs-on: ubuntu-latest
strategy:
matrix:
kustomize-version: ["4.5.2"]
needs: build

steps:
# Checkout
- uses: actions/[email protected]

# Download build artifacts
- name: 'Download build-artifacts'
uses: actions/[email protected]
with:
name: _dist
path: _dist

# Build image
- name: Build image
env:
DOCKER_BUILDKIT: 1
run: docker build --build-arg KUSTOMIZE_VERSION=${{ matrix.kustomize-version }} -t test-kustomize:${{ matrix.kustomize-version }} test/kustomize/

# Run tests
- name: Run tests
run: docker run -v `pwd`/_dist:/_dist test-kustomize:${{ matrix.kustomize-version }}


#
#
# Test deploy to k3d
Expand All @@ -101,7 +67,7 @@ jobs:

# Setup k3d
- name: Setup k3d
uses: rinx/[email protected].3
uses: rinx/[email protected].4
with:
skipClusterCreation: true

Expand Down Expand Up @@ -129,7 +95,7 @@ jobs:
#
publish:
runs-on: ubuntu-latest
needs: [test-kustomize, test-k3d, test-terraform]
needs: [test-k3d, test-terraform]

steps:
# Download build artifacts
Expand All @@ -149,35 +115,14 @@ jobs:

#
#
# Promote tagged releases
# from `dev.catalog.kubestack.com` to `catalog.kubestack.com`
promote:
# trigger promotion by tagging release
trigger-promote:
runs-on: ubuntu-latest
needs: publish
# promote only for tags
if: startsWith(github.ref, 'refs/tags/')
if: startsWith(github.ref, 'refs/heads/release-')

steps:
# Setup gcloud CLI
- uses: google-github-actions/[email protected]
with:
service_account_key: ${{ secrets.GCLOUD_AUTH }}

# Promote archive
- uses: actions/[email protected]
- run: |
export NAME=$(echo $GITHUB_REF | sed -e "s#^refs/tags/##")
set +e
while true
do
gsutil cp gs://dev.catalog.kubestack.com/${NAME}.zip gs://catalog.kubestack.com/${NAME}.zip &&\
gsutil cp gs://dev.catalog.kubestack.com/module-${NAME}.zip gs://catalog.kubestack.com/module-${NAME}.zip &&\
break
sleep 15
done
# Check promotion
- name: Check promotion
run: |
export NAME=$(echo $GITHUB_REF | sed -e "s#^refs/tags/##")
wget https://storage.googleapis.com/catalog.kubestack.com/${NAME}.zip
wget https://storage.googleapis.com/catalog.kubestack.com/module-${NAME}.zip
export TAG=$(echo $GITHUB_REF | sed -e "s#^refs/heads/release-##")
git tag $TAG
43 changes: 43 additions & 0 deletions .github/workflows/promote.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Promote

on:
push:
branches:
- "!*" # do not run for branches
tags:
- "*" # run for tags

jobs:
#
#
# Promote tagged releases
# from `dev.catalog.kubestack.com` to `catalog.kubestack.com`
promote:
runs-on: ubuntu-latest
needs: publish
# promote only for tags
if: startsWith(github.ref, 'refs/tags/')

steps:
# Setup gcloud CLI
- uses: google-github-actions/[email protected]
with:
service_account_key: ${{ secrets.GCLOUD_AUTH }}

# Promote archive
- run: |
export TAG=$(echo $GITHUB_REF | sed -e "s#^refs/tags/##")
export NAME=$(echo $TAG | sed -r 's#-v[0-9]+.*$##')
set +e
while true
do
gsutil cp gs://dev.catalog.kubestack.com/module-${NAME}-${GITHUB_SHA}.zip gs://catalog.kubestack.com/module-${TAG}.zip &&\
break
sleep 15
done
# Check promotion
- name: Check promotion
run: |
export TAG=$(echo $GITHUB_REF | sed -e "s#^refs/tags/##")
wget https://storage.googleapis.com/catalog.kubestack.com/module-${TAG}.zip
57 changes: 0 additions & 57 deletions test/kustomize/Dockerfile

This file was deleted.

12 changes: 0 additions & 12 deletions test/kustomize/Pipfile

This file was deleted.

30 changes: 0 additions & 30 deletions test/kustomize/Pipfile.lock

This file was deleted.

Loading

0 comments on commit 0ea4488

Please sign in to comment.