Skip to content

Commit

Permalink
add support for nightly release
Browse files Browse the repository at this point in the history
  • Loading branch information
mmulholla committed Sep 20, 2023
1 parent 536bbca commit 56e0fdf
Show file tree
Hide file tree
Showing 10 changed files with 365 additions and 181 deletions.
42 changes: 41 additions & 1 deletion .github/workflows/pr-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ on:
pull_request:
types: [opened, synchronize, reopened]
branches: [ main ]
repository_dispatch:
types: [primazactl-test]

env:
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}

jobs:
build:
Expand All @@ -13,7 +18,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "^1.19"
go-version: "^1.20"

- name: Set up Python
uses: actions/setup-python@v4
Expand All @@ -27,19 +32,54 @@ jobs:
- name: Lint python
run: make lint

- name: Set Version and Images
id: sets-version
run: |
# set version based on job type
if [[ "${{github.event_name}}" == "repository_dispatch" ]]; then
primaza_version=${{ github.event.client_payload.version }}
echo "GIT_ORG=${{ github.event.client_payload.organization }}" >> $GITHUB_ENV
echo "RUN_FROM=release" >> $GITHUB_ENV
echo "VERSION=$primaza_version" >> $GITHUB_ENV
else
echo "RUN_FROM=config" >> $GITHUB_ENV
echo "VERSION=latest" >> $GITHUB_ENV
fi
- name: run dry-run
run: make test-dry-run

- name: run test
run: make test-local-no-setup

- name: run test with users
env:
CLEAN: clusters
run: make test-users

- name: run test with output
env:
CLEAN: clusters
run: make test-output

- name: run apply command
env:
CLEAN: clusters
run: make test-apply

- name: run test version
if: ${{ env.VERSION == 'nightly' }}
env:
RUN_FROM: release
CLEAN: clusters
run: make test-version

- name: trigger release
if: ${{ github.event_name == 'repository_dispatch' }}
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.BOT_TOKEN }}
repository: ${{ github.repository_owner }}/primazactl
event-type: primazactl-release
client-payload: '{"version": "${{ env.VERSION }}",
"organization": "${{ env.GIT_ORG }}"}'
40 changes: 22 additions & 18 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ on:
description: "create a version for primazctl"
required: true
default: "latest"
organization:
description: "git organization from which to get the primaza release"
required: true
default: "primaza"
repository_dispatch:
types: [primazactl-release]

permissions:
contents: write
Expand All @@ -26,24 +32,31 @@ jobs:
python-version: "3.10"
architecture: "x64"

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "^1.20"

- name: Checkout code
uses: actions/checkout@v3

- name: Set Version and Manifests
- name: Set Version and Draft release
run: |
# set version based on dispatch type
version="latest"
draft_release="true"
if [[ "${{github.event_name}}" == "workflow_dispatch" ]]; then
version=${{ github.event.inputs.version }}
draft_release="false"
echo "GIT_ORG=${{ github.event.inputs.organization }}" >> $GITHUB_ENV
elif [[ "${{github.ref_type}}" == "tag" ]]; then
version=${{ github.ref_name }}
elif [[ "${{github.event_name}}" == "repository_dispatch" ]]; then
version=${{ github.event.client_payload.version }}
draft_release="false"
echo "GIT_ORG=${{ github.event.client_payload.organization }}" >> $GITHUB_ENV
fi
echo "VERSION=$version" >> $GITHUB_ENV
echo "PRIMAZA_CTL_VERSION=$version" >> $GITHUB_ENV
echo "PRIMAZA_CONFIG_FILE=primaza_main_config_$version.yaml" >> $GITHUB_ENV
echo "WORKER_CONFIG_FILE=primaza_worker_config_$version.yaml" >> $GITHUB_ENV
echo "APPLICATION_AGENT_CONFIG_FILE=application_agent_config_$version.yaml" >> $GITHUB_ENV
echo "SERVICE_AGENT_CONFIG_FILE=service_agent_config_$version.yaml" >> $GITHUB_ENV
echo "DRAFT_RELEASE=$draft_release" >> $GITHUB_ENV
- name: Test and make manifests
id: test-and-manifests
Expand All @@ -55,15 +68,14 @@ jobs:
run: make single-binary

- name: Delete previous release and tag
if: ${{ env.VERSION == 'latest' }}
if: ${{ env.VERSION == 'latest' || env.VERSION == 'nightly' }}
uses: dev-drprasad/[email protected]
with:
delete_release: true # default: false
tag_name: ${{ env.VERSION }} # tag name to delete
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


- name: Release for tag event
if: ${{ github.ref_type == 'tag' }}
uses: softprops/action-gh-release@v1
Expand All @@ -73,22 +85,14 @@ jobs:
generate_release_notes: true
files: |
./out/venv3/dist/primazactl
${{ env.PRIMAZA_CONFIG_FILE }}
${{ env.WORKER_CONFIG_FILE }}
${{ env.APPLICATION_AGENT_CONFIG_FILE }}
${{ env.SERVICE_AGENT_CONFIG_FILE }}
- name: Release for non tag events
if: ${{ github.ref_type != 'tag' }}
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.VERSION }}
body: "Release version ${{ env.VERSION }}"
draft: true
draft: ${{ env.DRAFT_RELEASE }}
generate_release_notes: true
files: |
./out/venv3/dist/primazactl
${{ env.PRIMAZA_CONFIG_FILE }}
${{ env.WORKER_CONFIG_FILE }}
${{ env.APPLICATION_AGENT_CONFIG_FILE }}
${{ env.SERVICE_AGENT_CONFIG_FILE }}
99 changes: 75 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ PRIMAZA_CTL_VERSION ?= $(shell git describe --tags --always --abbrev=8 --dirty)
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

IMG ?= ghcr.io/primaza/primaza:$(VERSION)
IMG_APP ?= ghcr.io/primaza/primaza-agentapp:$(VERSION)
IMG_SVC ?= ghcr.io/primaza/primaza-agentsvc:$(VERSION)
IMG_APP_LOCAL ?= agentapp:$(VERSION)
IMG_SVC_LOCAL ?= agentsvc:$(VERSION)
# SET RUN_FROM to config the create config files or release to use a release
RUN_FROM ?= config
GIT_ORG ?= primaza
IMG = ghcr.io/$(GIT_ORG)/primaza:$(VERSION)
IMG_APP = ghcr.io/$(GIT_ORG)/primaza-agentapp:$(VERSION)
IMG_SVC = ghcr.io/$(GIT_ORG)/primaza-agentsvc:$(VERSION)
IMG_APP_LOCAL = agentapp:$(VERSION)
IMG_SVC_LOCAL = agentsvc:$(VERSION)

# set CLEAN to "clusters" to only refresh clusters
CLEAN ?= all

PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))

Expand Down Expand Up @@ -87,10 +93,10 @@ APPLICATION_NAMESPACE ?= primaza-application
SERVICE_NAMESPACE ?= primaza-service
SERVICE_ACCOUNT_NAMESPACE ?= worker-sa

PRIMAZA_CONFIG_FILE ?= $(PRIMAZA_CONFIG_DIR)/primaza_config_$(VERSION).yaml
WORKER_CONFIG_FILE ?= $(PRIMAZA_CONFIG_DIR)/worker_config_$(VERSION).yaml
APPLICATION_AGENT_CONFIG_FILE ?= $(PRIMAZA_CONFIG_DIR)/application_agent_config_$(VERSION).yaml
SERVICE_AGENT_CONFIG_FILE ?= $(PRIMAZA_CONFIG_DIR)/service_agent_config_$(VERSION).yaml
PRIMAZA_CONFIG_FILE ?= $(PRIMAZA_CONFIG_DIR)/control_plane_config_$(VERSION).yaml
WORKER_CONFIG_FILE ?= $(PRIMAZA_CONFIG_DIR)/crds_config_$(VERSION).yaml
APPLICATION_AGENT_CONFIG_FILE ?= $(PRIMAZA_CONFIG_DIR)/application_namespace_config_$(VERSION).yaml
SERVICE_AGENT_CONFIG_FILE ?= $(PRIMAZA_CONFIG_DIR)/service_namespace_config_$(VERSION).yaml

KIND_CONFIG_DIR ?= $(SCRIPTS_DIR)/src/primazatest/config
TENANT_KIND_CONFIG_FILE ?= $(KIND_CONFIG_DIR)/kind-main.yaml
Expand Down Expand Up @@ -150,7 +156,10 @@ image:
docker tag $(IMG_SVC) $(IMG_SVC_LOCAL)

.PHONY: kind-clusters
kind-clusters: config image
kind-clusters: image
ifeq ($(CLEAN),all)
$(MAKE) image
endif
-kind delete cluster --name $(KIND_CLUSTER_TENANT_NAME)
-kind delete cluster --name $(KIND_CLUSTER_JOIN_NAME)
kind create cluster --config $(TENANT_KIND_CONFIG_FILE) --name $(KIND_CLUSTER_TENANT_NAME) && kubectl wait --for condition=Ready nodes --all --timeout=600s
Expand All @@ -164,7 +173,13 @@ kind-clusters: config image
kind load docker-image $(IMG_SVC_LOCAL) --name $(KIND_CLUSTER_JOIN_NAME)

.PHONY: setup-test
setup-test: clean image primazactl config kind-clusters
setup-test: clean kind-clusters
ifeq ($(CLEAN),all)
$(MAKE) primazactl
endif
ifeq ($(RUN_FROM),config)
$(MAKE) config
endif

.PHONY: clone
clone: clean-temp
Expand All @@ -185,6 +200,8 @@ primazactl: ## Setup virtual environment

.PHONY: single-binary
single-binary: ## Release primazactl as single binary
echo '__version__ = "$(PRIMAZA_CTL_VERSION)"' > $(VERSION_FILE)
echo '__primaza_version__ = "$(VERSION)"' >> $(VERSION_FILE)
-rm -rf $(PYTHON_VENV_DIR)
python3 -m venv $(PYTHON_VENV_DIR)
$(PYTHON_VENV_DIR)/bin/pip3 install --upgrade pyinstaller
Expand All @@ -204,31 +221,55 @@ lint: primazactl ## Check python code

.PHONY: test-local
test-local: setup-test
ifeq ($(RUN_FROM),config)
$(PYTHON_VENV_DIR)/bin/primazatest -p $(PYTHON_VENV_DIR) -e $(WORKER_CONFIG_FILE) -f $(PRIMAZA_CONFIG_FILE) -c $(KUBE_KIND_CLUSTER_JOIN_NAME) -m $(KUBE_KIND_CLUSTER_TENANT_NAME) -a $(APPLICATION_AGENT_CONFIG_FILE) -s $(SERVICE_AGENT_CONFIG_FILE) -j $(SERVICE_ACCOUNT_NAMESPACE)
else
$(PYTHON_VENV_DIR)/bin/primazatest -p $(PYTHON_VENV_DIR) -c $(KUBE_KIND_CLUSTER_JOIN_NAME) -m $(KUBE_KIND_CLUSTER_TENANT_NAME) -j $(SERVICE_ACCOUNT_NAMESPACE) -v $(VERSION) -g $(GIT_ORG)
endif

.PHONY: test-version
test-version: setup-test
$(PYTHON_VENV_DIR)/bin/primazatest -p $(PYTHON_VENV_DIR) -c $(KUBE_KIND_CLUSTER_JOIN_NAME) -m $(KUBE_KIND_CLUSTER_TENANT_NAME) -v $(VERSION) -g $(GIT_ORG)

.PHONY: test-released
test-released:
make kind-clusters
$(PYTHON_VENV_DIR)/bin/primazatest -p $(PYTHON_VENV_DIR) -v $(VERSION) -c $(KUBE_KIND_CLUSTER_JOIN_NAME) -m $(KUBE_KIND_CLUSTER_TENANT_NAME)
$(PYTHON_VENV_DIR)/bin/primazatest -p $(PYTHON_VENV_DIR) -v $(VERSION) -c $(KUBE_KIND_CLUSTER_JOIN_NAME) -m $(KUBE_KIND_CLUSTER_TENANT_NAME) -g $(GIT_ORG)

.PHONY: test-users
test-users: setup-test create-users
ifeq ($(RUN_FROM),config)
$(PYTHON_VENV_DIR)/bin/primazatest -u -i $(OUTPUT_DIR)/users -p $(PYTHON_VENV_DIR) -e $(WORKER_CONFIG_FILE) -f $(PRIMAZA_CONFIG_FILE) -c $(KUBE_KIND_CLUSTER_JOIN_NAME) -m $(KUBE_KIND_CLUSTER_TENANT_NAME) -a $(APPLICATION_AGENT_CONFIG_FILE) -s $(SERVICE_AGENT_CONFIG_FILE)
else
$(PYTHON_VENV_DIR)/bin/primazatest -u -i $(OUTPUT_DIR)/users -p $(PYTHON_VENV_DIR) -c $(KUBE_KIND_CLUSTER_JOIN_NAME) -m $(KUBE_KIND_CLUSTER_TENANT_NAME) -v $(VERSION) -g $(GIT_ORG)
endif

.PHONY: test-dry-run
test-dry-run: setup-test
ifeq ($(RUN_FROM),config)
$(PYTHON_VENV_DIR)/bin/primazatest -d -p $(PYTHON_VENV_DIR) -e $(WORKER_CONFIG_FILE) -f $(PRIMAZA_CONFIG_FILE) -c $(KUBE_KIND_CLUSTER_JOIN_NAME) -m $(KUBE_KIND_CLUSTER_TENANT_NAME) -a $(APPLICATION_AGENT_CONFIG_FILE) -s $(SERVICE_AGENT_CONFIG_FILE) -t $(OPTIONS_FILE)
else
$(PYTHON_VENV_DIR)/bin/primazatest -d -p $(PYTHON_VENV_DIR) -c $(KUBE_KIND_CLUSTER_JOIN_NAME) -m $(KUBE_KIND_CLUSTER_TENANT_NAME) -v $(VERSION) -t $(OPTIONS_FILE) -g $(GIT_ORG)
endif

.PHONY test-local-no-setup:
ifeq ($(RUN_FROM),config)
$(PYTHON_VENV_DIR)/bin/primazatest -p $(PYTHON_VENV_DIR) -e $(WORKER_CONFIG_FILE) -f $(PRIMAZA_CONFIG_FILE) -c $(KUBE_KIND_CLUSTER_JOIN_NAME) -m $(KUBE_KIND_CLUSTER_TENANT_NAME) -a $(APPLICATION_AGENT_CONFIG_FILE) -s $(SERVICE_AGENT_CONFIG_FILE)
else
$(PYTHON_VENV_DIR)/bin/primazatest -p $(PYTHON_VENV_DIR) -c $(KUBE_KIND_CLUSTER_JOIN_NAME) -m $(KUBE_KIND_CLUSTER_TENANT_NAME) -v $(VERSION) -g $(GIT_ORG)
endif

.PHONY: test-output
test-output: setup-test
ifeq ($(RUN_FROM),config)
$(PYTHON_VENV_DIR)/bin/primazatest -o -p $(PYTHON_VENV_DIR) -e $(WORKER_CONFIG_FILE) -f $(PRIMAZA_CONFIG_FILE) -c $(KUBE_KIND_CLUSTER_JOIN_NAME) -m $(KUBE_KIND_CLUSTER_TENANT_NAME) -a $(APPLICATION_AGENT_CONFIG_FILE) -s $(SERVICE_AGENT_CONFIG_FILE)
else
$(PYTHON_VENV_DIR)/bin/primazatest -o -p $(PYTHON_VENV_DIR) -c $(KUBE_KIND_CLUSTER_JOIN_NAME) -m $(KUBE_KIND_CLUSTER_TENANT_NAME) -v $(VERSION) -g $(GIT_ORG)
endif

.PHONY: test-apply
test-apply: setup-test
$(PYTHON_VENV_DIR)/bin/primazatest -t $(OPTIONS_FILE) -p $(PYTHON_VENV_DIR)
$(PYTHON_VENV_DIR)/bin/primazatest -t $(OPTIONS_FILE) -p $(PYTHON_VENV_DIR) -v $(VERSION) -g $(GIT_ORG)

.PHONY: create-users
create-users: primazactl
Expand All @@ -245,20 +286,30 @@ create-users: primazactl
.PHONY: test
test: setup-test test-local test-released

.PHONY: clean
clean:
ifeq ($(CLEAN),clusters)
$(MAKE) delete-clusters
else
$(MAKE) clean-all
endif

.PHONY: clean-temp
clean-temp:
-chmod 755 $(TEMP_DIR)/bin/k8s/*
rm -rf $(TEMP_DIR)
-rm -rf $(TEMP_DIR)

.PHONY: clean-all
clean-all: clean-temp delete-clusters
-rm -rf $(OUTPUT_DIR)
-rm -rf $(SCRIPTS_DIR)/build
-rm -rf $(SCRIPTS_DIR)/dist
-rm -rf $(SCRIPTS_DIR)/src/rh_primaza_control.egg-info
-rm -rf $(LOCALBIN)
-docker image rm $(IMG_APP_LOCAL)
-docker image rm $(IMG_SVC_LOCAL)

.PHONY: clean
clean: clean-temp
rm -rf $(OUTPUT_DIR)
rm -rf $(SCRIPTS_DIR)/build
rm -rf $(SCRIPTS_DIR)/dist
rm -rf $(SCRIPTS_DIR)/src/rh_primaza_control.egg-info
rm -rf $(LOCALBIN)
.PHONY: delete-clusters
delete-clusters:
-kind delete cluster --name $(KIND_CLUSTER_TENANT_NAME)
-kind delete cluster --name $(KIND_CLUSTER_JOIN_NAME)

-docker image rm $(IMG_APP_LOCAL)
-docker image rm $(IMG_SVC_LOCAL)
8 changes: 4 additions & 4 deletions scripts/src/primazactl/cmd/apply/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"tenant": DEFAULT_TENANT,
"version": __primaza_version__,
"kubeconfig": from_env(),
"tenant_config": "primaza_config_latest.yaml",
"worker_config": "worker_config_latest.yaml",
"service_agent_config": "service_agent_config_latest.yaml",
"app_agent_config": "application_agent_config_latest.yaml",
"tenant_config": "control_plane_config_latest.yaml",
"worker_config": "crds_config_latest.yaml",
"service_agent_config": "service_namespace_config_latest.yaml",
"app_agent_config": "application_namespace_config_latest.yaml",
"service_account_namespace": WORKER_NAMESPACE}
3 changes: 1 addition & 2 deletions scripts/src/primazactl/kube/customnamespaced.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ def create(self):
raise e
else:
logger.log_info(f'UNCHANGED: {self.body["kind"]} '
f'{self.body["metadata"]["name"]} '
'already exists',
f'{self.body["metadata"]["name"]} already exists',
settings.dry_run_active())

def read(self) -> client.V1Namespace | None:
Expand Down
20 changes: 15 additions & 5 deletions scripts/src/primazactl/kubectl/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
PRIMAZA_CONFIG: str = "primaza_main_config"
WORKER_CONFIG: str = "primaza_worker_config"
APP_AGENT_CONFIG: str = "application_agent_config"
SVC_AGENT_CONFIG: str = "service_agent_config"
REPOSITORY: str = "primaza/primazactl"
import os

PRIMAZA_CONFIG: str = "control_plane_config"
WORKER_CONFIG: str = "crds_config"
APP_AGENT_CONFIG: str = "application_namespace_config"
SVC_AGENT_CONFIG: str = "service_namespace_config"
REPOSITORY: str = "primaza/primaza"
TEST_REPOSITORY_OVERRIDE: str = "primaza-test-only-repository-override"


def get_repository():
override_repo = os.getenv(TEST_REPOSITORY_OVERRIDE)
if override_repo:
return override_repo
return REPOSITORY
Loading

0 comments on commit 56e0fdf

Please sign in to comment.