Compare commits
No commits in common. "69c6b35d17aaf7f0d248497f7579e3023e1e29ee" and "1508d44120bf7c1a7951fb6270ae9b656a56be64" have entirely different histories.
69c6b35d17
...
1508d44120
142
init-app
142
init-app
|
@ -1,142 +0,0 @@
|
||||||
#!/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 --branch "feat/automation" ${SKELL_GIT_URL} ${appDest}
|
|
||||||
|
|
||||||
cd ${appDest}
|
|
||||||
rm -rf .git
|
|
||||||
|
|
||||||
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}"
|
|
5
main.mk
5
main.mk
|
@ -36,6 +36,7 @@ define release_image
|
||||||
docker push $(IMAGE_REPO)/$1:$(IMAGE_VERSION)-$(DAY_SUFFIX_TAG)
|
docker push $(IMAGE_REPO)/$1:$(IMAGE_VERSION)-$(DAY_SUFFIX_TAG)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
|
||||||
#list:
|
#list:
|
||||||
build: ${IMAGES_DIR}/*
|
build: ${IMAGES_DIR}/*
|
||||||
@for name in $(basename $(notdir $^)); do \
|
@for name in $(basename $(notdir $^)); do \
|
||||||
|
@ -73,8 +74,4 @@ tools/bin/bash_unit:
|
||||||
mkdir -p tools/bin
|
mkdir -p tools/bin
|
||||||
cd tools/bin && bash <(curl -s https://raw.githubusercontent.com/pgrange/bash_unit/master/install.sh)
|
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
|
##include recipes/*.mk
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
kind: Cluster
|
kind: Cluster
|
||||||
apiVersion: kind.x-k8s.io/v1alpha4
|
apiVersion: kind.x-k8s.io/v1alpha4
|
||||||
name: dev-cluster
|
name: mse-dev
|
||||||
networking:
|
networking:
|
||||||
podSubnet: "10.110.0.0/16"
|
podSubnet: "10.110.0.0/16"
|
||||||
serviceSubnet: "10.115.0.0/16"
|
serviceSubnet: "10.115.0.0/16"
|
||||||
|
|
|
@ -8,24 +8,24 @@ configurations:
|
||||||
- ./configurations/cnpg-cluster.yaml
|
- ./configurations/cnpg-cluster.yaml
|
||||||
|
|
||||||
resources:
|
resources:
|
||||||
- ./resources/MYAPPLICATION-cnpg-cluster.yaml
|
- ./resources/app-cnpg-cluster.yaml
|
||||||
|
|
||||||
secretgenerator:
|
secretgenerator:
|
||||||
- name: MYAPPLICATION-postgres-admin
|
- name: app-postgres-admin
|
||||||
type: secret
|
type: secret
|
||||||
literals:
|
literals:
|
||||||
- username=postgres
|
- username=postgres
|
||||||
- password=notsosecret
|
- password=notsosecret
|
||||||
- name: MYAPPLICATION-postgres-user
|
- name: app-postgres-user
|
||||||
type: Secret
|
type: Secret
|
||||||
literals:
|
literals:
|
||||||
- username=MYAPPLICATION
|
- username=app
|
||||||
- password=NotSoSecretButThisIsBad
|
- password=NotSoSecretButThisIsBad
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
- name: MYAPPLICATION_DATABASE_SERVICE_NAME
|
- name: APP_DATABASE_SERVICE_NAME
|
||||||
objref:
|
objref:
|
||||||
name: MYAPPLICATION-postgres
|
name: app-postgres
|
||||||
kind: Cluster
|
kind: Cluster
|
||||||
apiVersion: postgresql.cnpg.io/v1
|
apiVersion: postgresql.cnpg.io/v1
|
||||||
fieldref:
|
fieldref:
|
|
@ -1,17 +1,17 @@
|
||||||
apiVersion: postgresql.cnpg.io/v1
|
apiVersion: postgresql.cnpg.io/v1
|
||||||
kind: Cluster
|
kind: Cluster
|
||||||
metadata:
|
metadata:
|
||||||
name: MYAPPLICATION-postgres
|
name: app-postgres
|
||||||
spec:
|
spec:
|
||||||
instances: 3
|
instances: 3
|
||||||
primaryUpdateStrategy: unsupervised
|
primaryUpdateStrategy: unsupervised
|
||||||
superuserSecret:
|
superuserSecret:
|
||||||
name: MYAPPLICATION-postgres-admin
|
name: app-postgres-admin
|
||||||
bootstrap:
|
bootstrap:
|
||||||
initdb:
|
initdb:
|
||||||
database: MYAPPLICATION
|
database: app
|
||||||
owner: MYAPPLICATION
|
owner: app
|
||||||
secret:
|
secret:
|
||||||
name: MYAPPLICATION-postgres-user
|
name: app-postgres-user
|
||||||
storage:
|
storage:
|
||||||
size: 20Gi
|
size: 20Gi
|
|
@ -1,10 +1,10 @@
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
|
|
||||||
namePrefix: MYAPPLICATION-
|
namePrefix: app-
|
||||||
|
|
||||||
components:
|
components:
|
||||||
- components/MYAPPLICATION-cnpg
|
- components/app-cnpg
|
||||||
|
|
||||||
resources:
|
resources:
|
||||||
- resources/MYAPPLICATION-kube
|
- resources/app-kube
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
|
||||||
kind: Kustomization
|
|
||||||
|
|
||||||
resources:
|
|
||||||
- ./resources/MYAPPLICATION-service.yaml
|
|
||||||
- ./resources/MYAPPLICATION-deployment.yaml
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
|
||||||
|
resources:
|
||||||
|
- ./resources/app-service.yaml
|
||||||
|
- ./resources/app-deployment.yaml
|
|
@ -2,26 +2,26 @@ apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
io.kompose.service: MYAPPLICATION
|
io.kompose.service: app
|
||||||
name: MYAPPLICATION
|
name: app
|
||||||
spec:
|
spec:
|
||||||
replicas: 3
|
replicas: 3
|
||||||
|
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
io.kompose.service: MYAPPLICATION
|
io.kompose.service: app
|
||||||
strategy:
|
strategy:
|
||||||
type: Recreate
|
type: Recreate
|
||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
io.kompose.service: MYAPPLICATION
|
io.kompose.service: app
|
||||||
spec:
|
spec:
|
||||||
restartPolicy: Always
|
restartPolicy: Always
|
||||||
containers:
|
containers:
|
||||||
- image: reg.cadoles.com/cadoles/MYAPPLICATION-kube
|
- image: reg.cadoles.com/cadoles/app-kube
|
||||||
imagePullPolicy: Always
|
imagePullPolicy: Always
|
||||||
name: MYAPPLICATION-php-fpm
|
name: app-php-fpm
|
||||||
args: ["/usr/sbin/php-fpm81", "-F", "-e"]
|
args: ["/usr/sbin/php-fpm81", "-F", "-e"]
|
||||||
resources: {}
|
resources: {}
|
||||||
env:
|
env:
|
||||||
|
@ -33,22 +33,22 @@ spec:
|
||||||
value: 128m
|
value: 128m
|
||||||
- name: PHP_FPM_LOG_LEVEL
|
- name: PHP_FPM_LOG_LEVEL
|
||||||
value: warning
|
value: warning
|
||||||
- name: MYAPPLICATION_DATABASE_SERVICE_NAME
|
- name: APP_DATABASE_SERVICE_NAME
|
||||||
value: $(MYAPPLICATION_DATABASE_SERVICE_NAME)-rw
|
value: $(APP_DATABASE_SERVICE_NAME)-rw
|
||||||
- image: reg.cadoles.com/cadoles/MYAPPLICATION-kube
|
- image: reg.cadoles.com/cadoles/app-kube
|
||||||
imagePullPolicy: Always
|
imagePullPolicy: Always
|
||||||
name: MYAPPLICATION-nginx
|
name: app-nginx
|
||||||
args: ["/usr/sbin/nginx"]
|
args: ["/usr/sbin/nginx"]
|
||||||
env:
|
env:
|
||||||
- name: NGINX_MYAPPLICATION_UPSTREAM_BACKEND_SERVER
|
- name: NGINX_APP_UPSTREAM_BACKEND_SERVER
|
||||||
value: 127.0.0.1:9000
|
value: 127.0.0.1:9000
|
||||||
- name: NGINX_MYAPPLICATION_ROOT
|
- name: NGINX_APP_ROOT
|
||||||
value: "/public"
|
value: "/public"
|
||||||
- name: NGINX_MYAPPLICATION_PHP_INDEX
|
- name: NGINX_APP_PHP_INDEX
|
||||||
value: "/index.php"
|
value: "/index.php"
|
||||||
- name: NGINX_ERROR_LOG_LEVEL
|
- name: NGINX_ERROR_LOG_LEVEL
|
||||||
value: "warn"
|
value: "warn"
|
||||||
- name: NGINX_MYAPPLICATION_PHP_NON_FILE_PATTERN
|
- name: NGINX_APP_PHP_NON_FILE_PATTERN
|
||||||
value: "^/index\\.php(/|$)"
|
value: "^/index\\.php(/|$)"
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8080
|
- containerPort: 8080
|
|
@ -2,13 +2,13 @@ apiVersion: v1
|
||||||
kind: Service
|
kind: Service
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
io.kompose.service: MYAPPLICATION
|
io.kompose.service: app
|
||||||
name: MYAPPLICATION
|
name: app
|
||||||
spec:
|
spec:
|
||||||
type: ClusterIP
|
type: ClusterIP
|
||||||
ports:
|
ports:
|
||||||
- name: MYAPPLICATION-http
|
- name: app-http
|
||||||
port: 80
|
port: 80
|
||||||
targetPort: 8080
|
targetPort: 8080
|
||||||
selector:
|
selector:
|
||||||
io.kompose.service: MYAPPLICATION
|
io.kompose.service: app
|
|
@ -1,6 +1,6 @@
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
namespace: MYAPPLICATION-dev
|
namespace: app-dev
|
||||||
|
|
||||||
resources:
|
resources:
|
||||||
- ../../base
|
- ../../base
|
||||||
|
@ -8,7 +8,7 @@ resources:
|
||||||
- resources/ingress.yaml
|
- resources/ingress.yaml
|
||||||
|
|
||||||
patches:
|
patches:
|
||||||
- path: patches/MYAPPLICATION-update-replicas.yaml
|
- path: patches/update-replicas-for-app.yaml
|
||||||
- path: patches/add-registry-pull-secret.yaml
|
- path: patches/add-registry-pull-secret.yaml
|
||||||
target:
|
target:
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
|
|
|
@ -2,7 +2,7 @@ apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
io.kompose.service: MYAPPLICATION
|
io.kompose.service: app
|
||||||
name: MYAPPLICATION
|
name: app
|
||||||
spec:
|
spec:
|
||||||
replicas: 1
|
replicas: 1
|
|
@ -1,7 +1,7 @@
|
||||||
apiVersion: networking.k8s.io/v1
|
apiVersion: networking.k8s.io/v1
|
||||||
kind: Ingress
|
kind: Ingress
|
||||||
metadata:
|
metadata:
|
||||||
name: MYAPPLICATION
|
name: app
|
||||||
annotations:
|
annotations:
|
||||||
nginx.ingress.kubernetes.io/proxy-body-size: "138m"
|
nginx.ingress.kubernetes.io/proxy-body-size: "138m"
|
||||||
nginx.ingress.kubernetes.io/enable-cors: "true" #cf 01
|
nginx.ingress.kubernetes.io/enable-cors: "true" #cf 01
|
||||||
|
@ -9,13 +9,13 @@ metadata:
|
||||||
spec:
|
spec:
|
||||||
ingressClassName: nginx
|
ingressClassName: nginx
|
||||||
rules:
|
rules:
|
||||||
- host: MYAPPLICATION.dev.local
|
- host: app.dev.local
|
||||||
http:
|
http:
|
||||||
paths:
|
paths:
|
||||||
- path: /
|
- path: /
|
||||||
pathType: Prefix
|
pathType: Prefix
|
||||||
backend:
|
backend:
|
||||||
service:
|
service:
|
||||||
name: MYAPPLICATION
|
name: app
|
||||||
port:
|
port:
|
||||||
number: 8080
|
number: 8080
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Namespace
|
kind: Namespace
|
||||||
metadata:
|
metadata:
|
||||||
name: MYAPPLICATION-dev
|
name: app-dev
|
||||||
|
|
|
@ -29,7 +29,7 @@ build:
|
||||||
sha256: {}
|
sha256: {}
|
||||||
|
|
||||||
artifacts:
|
artifacts:
|
||||||
- image: reg.cadoles.com/cadoles/MYAPPLICATION-kube
|
- image: reg.cadoles.com/cadoles/app-kube
|
||||||
context: .
|
context: .
|
||||||
sync:
|
sync:
|
||||||
infer:
|
infer:
|
||||||
|
@ -41,7 +41,7 @@ build:
|
||||||
- composer.json
|
- composer.json
|
||||||
- composer.lock
|
- composer.lock
|
||||||
kaniko:
|
kaniko:
|
||||||
dockerfile: misc/images/MYAPPLICATION-kube/Dockerfile
|
dockerfile: misc/images/app-kube/Dockerfile
|
||||||
cache: {}
|
cache: {}
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
|
|
Loading…
Reference in New Issue