Skip to content

Commit

Permalink
build: feat/previews-to-aks (#719)
Browse files Browse the repository at this point in the history
* feat/previews-to-aks
* add slack mesage

---------

Co-authored-by: DickPostma <(ID)+(username)@users.noreply.github.com>
Co-authored-by: Morris Swertz <[email protected]>
Co-authored-by: marikaris <[email protected]>
  • Loading branch information
4 people authored Oct 15, 2024
1 parent 47b9af7 commit 41b5764
Show file tree
Hide file tree
Showing 17 changed files with 644 additions and 27 deletions.
107 changes: 80 additions & 27 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,40 @@
#
version: 2.1

parameters:
GHA_Actor:
type: string
default: ""
GHA_Event:
type: string
default: ""
GHA_Action:
type: string
default: ""
GHA_Meta:
type: string
default: ""

orbs:
slack: circleci/[email protected]

definitions:
build_config: &build_config
docker:
- image: molgenis/ci-build:1.2.3
working_directory: ~/repo
resource_class: large
environment:
JVM_OPTS: -Xmx3200m
GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.workers.max=2"
TERM: dumb



jobs:
build:
docker:
- image: eclipse-temurin:17.0.12_7-jdk-jammy
- image: molgenis/ci-build:1.2.3

working_directory: ~/repo
resource_class: large
Expand Down Expand Up @@ -38,30 +68,6 @@ jobs:
pwd
echo "$CIRCLE_WORKING_DIRECTORY"
- run:
name: update package manager
command: apt-get update

- run:
name: add packages for docker cli install
command: apt-get -y install gnupg lsb-release curl

- run:
name: update packages again
command: apt-get update

- run:
name: set repo keys for docker packages
command: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

- run:
name: add repo for docker packages
command: 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" | tee /etc/apt/sources.list.d/docker.list > /dev/null

- run:
name: update package manager again
command: apt-get update

- run:
name: Install Docker client
command: apt-get -y install docker-ce docker-ce-cli containerd.io
Expand Down Expand Up @@ -89,7 +95,7 @@ jobs:
- run:
name: Build Armadillo and R CICD image
command: |
./gradlew docker
./gradlew docker ci
./docker/bin/prepare.bash ci
- store_artifacts:
Expand Down Expand Up @@ -134,6 +140,20 @@ jobs:
dockerPush
fi
- run:
name: deploy preview to Azure
command: |
if [ "${CIRCLE_BRANCH}" != "master" ]; then
export $( cat build/ci.properties | xargs )
bash ci/set_kubectl_config-azure.sh
bash ci/create_or_update_k8s-azure.sh "preview-armadillo-pr-${CIRCLE_PULL_REQUEST##*/}" ${TAG_NAME} DELETE
curl -d "token=${SLACK_TOKEN}" \
-d "text=*<${CIRCLE_PULL_REQUEST}|Circle-CI » Armadillo » Armadillo-Service » PR-${CIRCLE_PULL_REQUEST##*/} #${CIRCLE_BUILD_NUM}>*
PR Preview available on https://preview-armadillo-pr-${CIRCLE_PULL_REQUEST##*/}.dev.molgenis.org" \
-d "channel=C0639V5KTCY" \
-X POST https://slack.com/api/chat.postMessage
fi
- run:
name: Make sure all images declared in docker-compose.yml are available and ready
command: |
Expand Down Expand Up @@ -197,8 +217,41 @@ jobs:
docker images ls
docker compose rm
delete-helm-preview:
environment:
GHA_PREVIEW_NR: << pipeline.parameters.GHA_Meta >>

docker:
- image: molgenis/ci-build:1.2.3

working_directory: ~/repo
resource_class: large

steps:
- checkout
- run:
name: delete preview on azure
command: |
export $( cat build/ci.properties | xargs )
bash ci/set_kubectl_config-azure.sh
kubectl delete namespace preview-emx2-pr-${GHA_PREVIEW_NR} || true
workflows:
version: 2
build-deploy:
unless:
equal: ["delete-pr-preview", << pipeline.parameters.GHA_Action >>]
jobs:
- build:
filters:
branches:
ignore: master

delete_preview:
when:
equal: [ "delete-pr-preview", << pipeline.parameters.GHA_Action >> ]
jobs:
- build
- delete-helm-preview



14 changes: 14 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
on:
pull_request:
types: [ closed ]
jobs:
trigger-circleci:
runs-on: ubuntu-latest
steps:
- name: Trigger CircleCI delete_preview workflow
id: "delete-pr-preview"
uses: CircleCI-Public/[email protected]
with:
GHA_Meta: ${{ github.event.number }}
env:
CCI_TOKEN: ${{ secrets.CCI_PREV_TOKEN }}
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ if (version.toString().endsWith('-SNAPSHOT')) {
imageName = "docker.io/molgenis/molgenis-armadillo-snapshot"
tagName = "${project.version.toString()}-${ext.hash}"
}
task ci(type: WriteProperties) {
outputFile file('build/ci.properties')
property 'TAG_NAME', tagName
}

docker {
name imageName
tags 'latest', tagName
Expand Down
39 changes: 39 additions & 0 deletions ci/create_or_update_k8s-azure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#this scripts takes arguments
NAME=$1
TAG_NAME=$2
DELETE=$3

echo "Using namespace $NAME"
echo "Using docker tag_name $TAG_NAME"
echo "Delete=$DELETE"

REPO=molgenis/molgenis-armadillo
if [[ $TAG_NAME == *"SNAPSHOT"* ]]; then
REPO=molgenis/molgenis-armadillo-snapshot
fi
echo "Using repositorie $REPO"

# delete if exists
# Create certs from environement
echo ${CERTDEVMOLGENIS_KEY} | base64 --decode >> /tmp/cert_key
echo ${CERTDEVMOLGENIS_PEM} | base64 --decode >> /tmp/cert_pem

# wait for deletion to complete
kubectl delete namespace $NAME || true
sleep 15s
kubectl create namespace $NAME
kubectl create secret tls "dev.molgenis.org" --key /tmp/cert_key --cert /tmp/cert_pem -n ${NAME}

helm upgrade --install ${NAME} ./helm-chart --namespace ${NAME} \
--set ingress.hosts[0].paths[0].path=/ \
--set ingress.hosts[0].paths[0].pathType=ImplementationSpecific \
--set ingress.hosts[0].host=${NAME}.dev.molgenis.org \
--set ingress.tls[0].host=${NAME}.dev.molgenis.org \
--set ingress.tls[0].secretName=dev.molgenis.org \
--set adminPassword=adminArmadillo! \
--set image.tag=${TAG_NAME} \
--set image.pullPolicy=Always \

rm /tmp/cert_key
rm /tmp/cert_pem

9 changes: 9 additions & 0 deletions ci/set_kubectl_config-azure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
KUBE_CLUSTER=$1
KUBE_TOKEN=$2

echo " logging in to azure with service principal and get kube config"
az login --service-principal --tenant ${AZURE_SP_TENANT} -u ${AZURE_CLIENT_ID} -p ${AZURE_CLIENT_SECRET}
az aks get-credentials -g ${RESOURCE_GROUP} -n ${RESOURCE_GROUP}

kubectl config set-cluster ${RESOURCE_GROUP}
kubectl config use-context ${RESOURCE_GROUP}
23 changes: 23 additions & 0 deletions helm-chart/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
6 changes: 6 additions & 0 deletions helm-chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: armadillo
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: "1.16.0"
22 changes: 22 additions & 0 deletions helm-chart/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "armadillo.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "armadillo.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "armadillo.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "armadillo.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
62 changes: 62 additions & 0 deletions helm-chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "armadillo.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "armadillo.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "armadillo.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "armadillo.labels" -}}
helm.sh/chart: {{ include "armadillo.chart" . }}
{{ include "armadillo.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "armadillo.selectorLabels" -}}
app.kubernetes.io/name: {{ include "armadillo.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "armadillo.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "armadillo.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
Loading

0 comments on commit 41b5764

Please sign in to comment.