Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: feat/previews-to-aks #719

Merged
merged 31 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ef5e405
feat/previews-to-aks
Mar 26, 2024
6683867
circleciconfig
Mar 26, 2024
9bf8d59
circleciconfig typo
Mar 26, 2024
c19f298
circleciconfig typo
Mar 26, 2024
dc8509e
Install azure tools
Mar 26, 2024
4fc9d14
tabs are evil
Mar 27, 2024
42835f1
tabs are evil
Mar 27, 2024
4060caf
Names
Mar 27, 2024
acdbe57
Add helm
Mar 27, 2024
e936279
Always delete ns
Mar 27, 2024
450c2c9
Always delete ns
Mar 27, 2024
5b0f3b9
Forgot to add tag in env
Mar 27, 2024
0d1a5d2
lets find out if we can use molgenis build
Mar 27, 2024
00ae33c
lets find out if we can use molgenis build
Mar 27, 2024
c2e0411
Add github action
May 13, 2024
65f0f48
Add github action
May 13, 2024
f34718f
Add Token
May 13, 2024
af57ec5
Merge branch 'master' into feat/previews-to-aks
mswertz May 28, 2024
7c60ab0
make preview step only run in master
mswertz May 28, 2024
ca77a46
move preview to be pushed before release script runs to be faster
mswertz May 28, 2024
20488a7
add slack mesage
mswertz May 28, 2024
e0c13b5
Update config.yml
mswertz May 29, 2024
626ddf8
Merge branch 'master' into feat/previews-to-aks
mswertz May 29, 2024
e012183
Merge branch 'master' into feat/previews-to-aks
mswertz Sep 13, 2024
678aff9
create new build
Oct 4, 2024
8e6e27f
don't build preview on master build
Oct 4, 2024
d72294c
don't build preview on master build
Oct 4, 2024
d1305fc
don't build preview on master build
Oct 4, 2024
6f7c1b5
don't build preview on master build
Oct 4, 2024
8f3c5e2
Move git workflows in the good directory
Oct 4, 2024
7de66e8
Merge branch 'master' into feat/previews-to-aks
marikaris Oct 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.10_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