14 Commits

Author SHA1 Message Date
b14b8e1b9a Merge pull request 'dev' (#15) from dev into test
Reviewed-on: #15
2023-06-22 13:54:48 +02:00
996e4bcde3 fix(patches): use correct patch file name 2023-06-22 13:54:48 +02:00
b3263f739a fix(patches): adding missing patch 2023-06-22 13:46:02 +02:00
80d03bf7e8 Merge pull request 'dev' (#9) from dev into test
Reviewed-on: #9
2023-06-22 12:12:01 +02:00
5eb1f4b610 Merge pull request 'fix(iniapp): using default stable branch' (#8) from fix/iniapp into dev
Reviewed-on: #8
2023-06-22 12:11:27 +02:00
0e16682b0f fix(iniapp): using default stable branch 2023-06-22 12:10:46 +02:00
6015496fa0 Merge pull request 'dev' (#6) from dev into test
Reviewed-on: #6
2023-06-22 12:06:06 +02:00
61c8b8d50b Merge pull request 'fix(k8s): naming variables correctly for nginx container' (#4) from fix/nginx into dev
Reviewed-on: #4
2023-06-22 12:02:55 +02:00
8af5526c7a fix(k8s): naming variables correctly for nginx container 2023-06-22 12:01:48 +02:00
96884e4e56 Merge pull request 'dev' (#2) from dev into test
Reviewed-on: #2
2023-06-22 11:46:33 +02:00
3f098b691a Merge pull request 'feat(jenkins): adding new default jenkins configuration' (#1) from feat/jenkins into dev
Reviewed-on: #1
2023-06-22 11:46:05 +02:00
aeb5a75cf1 feat(jenkins): adding new default jenkins configuration 2023-06-21 09:43:13 +02:00
69c6b35d17 feat(initApp): adding new script to start a project the "clean way" 2023-06-15 12:20:55 +02:00
34df7a153a clean(structure): using MYAPPLICATION instead of app 2023-06-15 12:20:55 +02:00
20 changed files with 234 additions and 58 deletions

25
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,25 @@
// Intégration de la librairie Cadoles (voir https://forge.cadoles.com/Cadoles/Jenkins)
@Library("cadoles") _
// Utilisation du pipeline partagé pour les applications Symfony de Cadoles
// Le nom de l'image Docker passée en paramètre vous permet de préciser l'environnement de test
// de votre application Symfony
symfonyAppPipeline('ubuntu:22.04', [
'hooks': [
// Run docker image build, verification and publication stages
'postSymfonyAppPipeline': {
stage('Build and publish docker images') {
// Retrieve current tag
String currentTag = sh(script: 'git tag --points-at HEAD | head -n 1', returnStdout: true).trim()
// Retrieve default tag
String defaultTag = sh(returnStdout: true, script: 'git describe --always').trim()
kubecontainer.buildAndPublishImage([
'imageName': 'reg.cadoles.com/pcaseiro/myapplication-standalone',
'imageTag': defaultTag,
'dockerfile': './misc/images/myapplication-standalone/Dockerfile',
'dryRun': false
])
}
}
]
])

View File

@ -1,10 +1,12 @@
################################
# Makefile for Cadoles SP
################################
##################################################
# Makefile for Cadoles Kubernetes Skeletor project
##################################################
IMAGE_REPO := reg.cadoles.com/cadoles
IMAGE_VERSION ?= 0.0.1
COMMIT_ID ?= $(shell git rev-parse --short --verify HEAD)
CURRENT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD | tr -c '[:alnum:]\n\r' '_'| tr '[:upper:]' '[:lower:]')
IMAGE_REPO ?= reg.cadoles.com/cadoles
IMAGE_VERSION ?= 0.0.1-$(CURRENT_BRANCH)
DAY_SUFFIX_TAG ?= $(shell date +%Y%m%d)
include main.mk

143
init-app Executable file
View File

@ -0,0 +1,143 @@
#!/bin/sh
#
# Initialize a new symfony app
#
DOCKERFILES_ROOT="misc/images"
KUSTOMIZE_DIR="misc/k8s/kustomization"
SKELL_GIT_URL="https://forge.cadoles.com/CadolesKube/symfony-kube-skeletor.git"
run_form() {
local conf_dest="${1}"
echo "Welcome !"
echo
read -p "What is your application name (myapp) ? " appName
local appName=${appName:-myapp}
read -p "Where do you want to start your versions ? (0.0.1) : " initVersion
local initVersion=${initVersion:-0.0.1}
read -p "List your standard git branches (stable staging dev) : " initBranches
local initBranches=${initBranches:-"stable staging dev"}
local branches=""
for br in ${initBranches}; do
branches="${branches}\"${br}\", "
done
read -p "Docker registry address (reg.cadoles.com) : " dockerRegistry
local dockerRegistry=${dockerRegistry:-reg.cadoles.com}
cat <<__EOF__ > ${conf_dest}
{
"app": {
"name": "${appName}",
"init_version": "${initVersion}",
"branches": [ ${branches::-2} ]
},
"registry": {
"address": "${dockerRegistry}"
}
}
__EOF__
}
create_docker_secret() {
local conf="${1}"
local registry=$(jq -cr ".registry.address" ${conf})
docker login ${registry}
mkdir -p ${KUSTOMIZE_DIR}/base/secrets/dockerconfig
mkdir -p ${KUSTOMIZE_DIR}/overlays/dev/secrets/dockerconfig
docker --config ${KUSTOMIZE_DIR}/base/secrets/dockerconfig login ${registry}
mv ${KUSTOMIZE_DIR}/base/secrets/dockerconfig/config.json ${KUSTOMIZE_DIR}/base/secrets/dockerconfig/.dockerconfigjson
cp ${KUSTOMIZE_DIR}/base/secrets/dockerconfig/.dockerconfigjson ${KUSTOMIZE_DIR}/overlays/dev/secrets/dockerconfig/.dockerconfigjson
}
init_app() {
local conf="${1}"
local appDest="${2}/${appName}"
jq empty ${conf}
if [ ${?} -ne 0 ]; then
echo "Invalid application configuration ${conf}"
return 3
fi
if [ ! -d ${appDest} ]; then
mkdir -p ${appDest}
else
echo "Error ${appDest} allready exists"
return 2
fi
git clone ${SKELL_GIT_URL} ${appDest}
cd ${appDest}
rm -rf .git
rm -rf init-app
echo "Setting Dockerfiles"
dirs=$(find ${DOCKERFILES_ROOT}/* -type d -name 'myapplication-*')
for d in ${dirs}; do
mv ${d} $(echo ${d} | sed "s/myapplication/${appName}/g")
done
echo "Setting Kustomization directories"
dirs=$(find ${KUSTOMIZE_DIR}/* -type d -name 'myapplication-*')
for d in ${dirs}; do
mv ${d} $(echo ${d} | sed "s/myapplication/${appName}/g")
done
echo "Setting Kustomization files"
dirs=$(find ${KUSTOMIZE_DIR}/* -type f -name 'myapplication-*')
for d in ${dirs}; do
mv ${d} $(echo ${d} | sed "s/myapplication/${appName}/g")
done
grep -rl "myapplication" ${KUSTOMIZE_DIR} | xargs sed -i "s/myapplication/${appName}/g"
echo "Setting Skaffold configuration"
sed -i "s/myapplication/${appName}/g" ${appDest}/skaffold.yaml
echo "Setting docker registry secrets"
create_docker_secret ${conf}
cd -
}
main() {
local cleanup="0"
if [ -n "${1}" ]; then
app_conf="$(pwd)/${1}"
else
cleanup="1"
app_conf=$(mktemp)
run_form "${app_conf}"
cat ${app_conf}
fi
local appName=$(jq -cr ".app.name" ${app_conf})
appName=${appName,,}
local appDest=${2:-"/tmp/${appName}"}
init_app ${app_conf} ${appDest}
if [ "${cleanup}" -eq 1 ]; then
rm -rf ${app_conf}
fi
}
CONFIG=""
DEST="/tmp"
while getopts "c:d:" option
do
case $option in
c) CONFIG=${OPTARG} ;;
d) DEST=${OPTARG} ;;
esac
done
main "${CONFIG}" "${DEST}"

18
main.mk
View File

@ -28,15 +28,14 @@ define install_trivy
endef
define release_image
docker tag $(IMAGE_REPO)/$1:$(IMAGE_VERSION) $(IMAGE_REPO)/$1:$(IMAGE_VERSION)-$(DAY_SUFFIX_TAG) ; \
docker tag $(IMAGE_REPO)/$1:$(IMAGE_VERSION) $(IMAGE_REPO)/$1:$(IMAGE_VERSION)-$(COMMIT_ID) ; \
docker tag $(IMAGE_REPO)/$1:$(IMAGE_VERSION) $(IMAGE_REPO)/$1:$(IMAGE_VERSION); \
docker tag $(IMAGE_REPO)/$1:$(IMAGE_VERSION) $(IMAGE_REPO)/$1:latest ; \
docker push $(IMAGE_REPO)/$1:latest ; \
docker tag $(IMAGE_REPO)/$1:$(IMAGE_VERSION) $(IMAGE_REPO)/$1:$(IMAGE_VERSION)-latest; \
docker push $(IMAGE_REPO)/$1:$(IMAGE_VERSION)-latest ; \
docker push $(IMAGE_REPO)/$1:$(IMAGE_VERSION) ; \
docker push $(IMAGE_REPO)/$1:$(IMAGE_VERSION)-$(DAY_SUFFIX_TAG)
docker push $(IMAGE_REPO)/$1:$(IMAGE_VERSION)-$(COMMIT_ID)
endef
#list:
build: ${IMAGES_DIR}/*
@for name in $(basename $(notdir $^)); do \
@ -58,9 +57,12 @@ release: ${IMAGES_DIR}/*
@for name in $(basename $(notdir $^)); do \
$(call release_image,$${name},base); \
done;\
git tag -f -a $(IMAGE_VERSION) -m "Version $(IMAGE_VERSION) released"; \
git tag -f -a $(IMAGE_VERSION)-$(COMMIT_ID) -m "Version $(IMAGE_VERSION)-$(COMMIT_ID) released"; \
git tag -f -a $(IMAGE_VERSION)-latest -m "Version $(IMAGE_VERSION)-latest released"; \
_release:
docker tag $(IMAGE_FULL_NAME):$(IMAGE_TAG) $(IMAGE_FULL_NAME):$(IMAGE_TAG)-$(IMAGE_VERSION)-$(DAY_SUFFIX_TAG)
docker tag $(IMAGE_FULL_NAME):$(IMAGE_TAG) $(IMAGE_FULL_NAME):$(IMAGE_TAG)-$(IMAGE_VERSION)-$(COMMIT_ID)
docker tag $(IMAGE_FULL_NAME):$(IMAGE_TAG) $(IMAGE_FULL_NAME):$(IMAGE_TAG)-$(IMAGE_VERSION)
docker tag $(IMAGE_FULL_NAME):$(IMAGE_TAG) $(IMAGE_FULL_NAME):$(IMAGE_TAG)-latest
docker push $(IMAGE_FULL_NAME):$(IMAGE_TAG)-$(IMAGE_VERSION)-$(DAY_SUFFIX_TAG)
@ -74,4 +76,8 @@ tools/bin/bash_unit:
mkdir -p tools/bin
cd tools/bin && bash <(curl -s https://raw.githubusercontent.com/pgrange/bash_unit/master/install.sh)
up:
skaffold dev -p dev --default-repo ${IMAGE_REPO}
##include recipes/*.mk

View File

@ -1,6 +1,6 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: mse-dev
name: dev-cluster
networking:
podSubnet: "10.110.0.0/16"
serviceSubnet: "10.115.0.0/16"

View File

@ -8,24 +8,24 @@ configurations:
- ./configurations/cnpg-cluster.yaml
resources:
- ./resources/app-cnpg-cluster.yaml
- ./resources/myapplication-cnpg-cluster.yaml
secretgenerator:
- name: app-postgres-admin
- name: myapplication-postgres-admin
type: secret
literals:
- username=postgres
- password=notsosecret
- name: app-postgres-user
- name: myapplication-postgres-user
type: Secret
literals:
- username=app
- username=myapplication
- password=NotSoSecretButThisIsBad
vars:
- name: APP_DATABASE_SERVICE_NAME
- name: myapplication_DATABASE_SERVICE_NAME
objref:
name: app-postgres
name: myapplication-postgres
kind: Cluster
apiVersion: postgresql.cnpg.io/v1
fieldref:

View File

@ -1,17 +1,17 @@
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: app-postgres
name: myapplication-postgres
spec:
instances: 3
primaryUpdateStrategy: unsupervised
superuserSecret:
name: app-postgres-admin
name: myapplication-postgres-admin
bootstrap:
initdb:
database: app
owner: app
database: myapplication
owner: myapplication
secret:
name: app-postgres-user
name: myapplication-postgres-user
storage:
size: 20Gi

View File

@ -1,10 +1,10 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: app-
namePrefix: myapplication-
components:
- components/app-cnpg
- components/myapplication-cnpg
resources:
- resources/app-kube
- resources/myapplication-kube

View File

@ -1,6 +0,0 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./resources/app-service.yaml
- ./resources/app-deployment.yaml

View File

@ -0,0 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./resources/myapplication-service.yaml
- ./resources/myapplication-deployment.yaml

View File

@ -2,26 +2,26 @@ apiVersion: apps/v1
kind: Deployment
metadata:
labels:
io.kompose.service: app
name: app
io.kompose.service: myapplication
name: myapplication
spec:
replicas: 3
selector:
matchLabels:
io.kompose.service: app
io.kompose.service: myapplication
strategy:
type: Recreate
template:
metadata:
labels:
io.kompose.service: app
io.kompose.service: myapplication
spec:
restartPolicy: Always
containers:
- image: reg.cadoles.com/cadoles/app-kube
- image: reg.cadoles.com/cadoles/myapplication-kube
imagePullPolicy: Always
name: app-php-fpm
name: myapplication-php-fpm
args: ["/usr/sbin/php-fpm81", "-F", "-e"]
resources: {}
env:
@ -33,11 +33,11 @@ spec:
value: 128m
- name: PHP_FPM_LOG_LEVEL
value: warning
- name: APP_DATABASE_SERVICE_NAME
value: $(APP_DATABASE_SERVICE_NAME)-rw
- image: reg.cadoles.com/cadoles/app-kube
- name: myapplication_DATABASE_SERVICE_NAME
value: $(myapplication_DATABASE_SERVICE_NAME)-rw
- image: reg.cadoles.com/cadoles/myapplication-kube
imagePullPolicy: Always
name: app-nginx
name: myapplication-nginx
args: ["/usr/sbin/nginx"]
env:
- name: NGINX_APP_UPSTREAM_BACKEND_SERVER

View File

@ -2,13 +2,13 @@ apiVersion: v1
kind: Service
metadata:
labels:
io.kompose.service: app
name: app
io.kompose.service: myapplication
name: myapplication
spec:
type: ClusterIP
ports:
- name: app-http
- name: myapplication-http
port: 80
targetPort: 8080
selector:
io.kompose.service: app
io.kompose.service: myapplication

View File

@ -1,6 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: app-dev
namespace: myapplication-dev
resources:
- ../../base
@ -8,7 +8,7 @@ resources:
- resources/ingress.yaml
patches:
- path: patches/update-replicas-for-app.yaml
- path: patches/myapplication-update-replicas.yaml
- path: patches/add-registry-pull-secret.yaml
target:
kind: Deployment

View File

@ -2,7 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
labels:
io.kompose.service: app
name: app
io.kompose.service: myapplication
name: myapplication
spec:
replicas: 1

View File

@ -1,7 +1,7 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app
name: myapplication
annotations:
nginx.ingress.kubernetes.io/proxy-body-size: "138m"
nginx.ingress.kubernetes.io/enable-cors: "true" #cf 01
@ -9,13 +9,13 @@ metadata:
spec:
ingressClassName: nginx
rules:
- host: app.dev.local
- host: myapplication.dev.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: app
name: myapplication
port:
number: 8080
number: 80

View File

@ -1,4 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: app-dev
name: myapplication-dev

View File

@ -29,7 +29,7 @@ build:
sha256: {}
artifacts:
- image: reg.cadoles.com/cadoles/app-kube
- image: reg.cadoles.com/cadoles/myapplication-kube
context: .
sync:
infer:
@ -41,7 +41,7 @@ build:
- composer.json
- composer.lock
kaniko:
dockerfile: misc/images/app-kube/Dockerfile
dockerfile: misc/images/myapplication-kube/Dockerfile
cache: {}
deploy: