1- # Add utility functions and scripts to the container
1+ # Include utility functions and scripts
22include scripts/makefile/*.mk
33
44.PHONY : all fast allfast provision si exec exec0 down clean dev drush info phpcs phpcbf hooksymlink clang cinsp compval watchdogval drupalrectorval upgradestatusval behat sniffers tests front front-install front-build clear-front lintval lint storybook back behatdl behatdi browser_driver browser_driver_stop statusreportval contentgen newlineeof localize local-settings redis-settings content patchval diff
3838CURDIR =$(shell pwd)
3939
4040# Execute php container as regular user
41- php = docker-compose exec -T --user $( CUID ) : $( CGID ) php ${1}
41+ php = kubectl exec -it deploy/sdc -c php -- su -s /bin/ash www-data -c " ${1}"
4242# Execute php container as root user
43- php-0 = docker-compose exec -T --user 0:0 php ${1}
43+ php-0 = kubectl exec -it deploy/sdc -c php -- ${1}
44+
45+ killall :
46+ /usr/local/bin/k3s-killall.sh
47+ /usr/local/bin/k3s-uninstall.sh
4448
4549ADDITIONAL_PHP_PACKAGES := tzdata graphicsmagick # php7-intl php7-redis wkhtmltopdf gnu-libiconv php7-pdo_pgsql postgresql-client postgresql-contrib
4650DC_MODULES := project_default_content better_normalizers default_content hal serialization
@@ -63,17 +67,24 @@ provision:
6367# Check if enviroment variables has been defined
6468ifeq ($(strip $(COMPOSE_PROJECT_NAME ) ) ,projectname)
6569 $(info Project name can not be default, please enter project name.)
66- $(eval COMPOSE_PROJECT_NAME = $(strip $(shell read -p "Project name: " REPLY;echo -n $$REPLY)))
70+ $(eval COMPOSE_PROJECT_NAME = $(strip $(shell read -p "Project name: " REPLY;echo -n $$REPLY))) # TODO: Sanitize lowercase/nospecialchar
6771 $(shell sed -i -e '/COMPOSE_PROJECT_NAME=/ s/=.*/=$(COMPOSE_PROJECT_NAME)/' .env)
6872 $(info Please review your project settings and run `make all` again.)
6973 exit 1
7074endif
7175ifdef DB_MOUNT_DIR
7276 $(shell [ ! -d $(DB_MOUNT_DIR) ] && mkdir -p $(DB_MOUNT_DIR) && chmod 777 $(DB_MOUNT_DIR))
7377endif
74- make -s down
78+ # make -s down
79+ @echo "Downloading and installing container orchestrator..."
80+ curl -sfL https://get.k3s.io | K3S_NODE_NAME=sdc K3S_KUBECONFIG_MODE="644" sh - # TODO: Check behavior if k3s already install + lock version
81+ curl -sfL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | sh - # TODO: rm $(which helm)
82+ # kubectl config view --raw >~/.kube/config # TODO: Simlink to /etc/rancher/k3s/k3s.yaml OR use helm install --kubeconfig=/etc/rancher/k3s/k3s.yaml sdc ./kubernetes/sdc-chart
7583 @echo "Build and run containers..."
76- docker-compose up -d --remove-orphans
84+ # TODO: Rename file
85+ kubectl apply -f kubernetes/sdc.yaml
86+ # helm install --kubeconfig=/etc/rancher/k3s/k3s.yaml sdc ./helm/ # https://github.com/k3s-io/k3s/issues/1126#issuecomment-567591888
87+ for i in {1..50}; do echo "Waiting for PHP container..." && kubectl exec -it deploy/sdc -c php -- "whoami" &> /dev/null && break || sleep 1; done; echo "Container is up !"
7788 # Set composer2 as default
7889 $(call php-0, ln -fs composer2 /usr/bin/composer)
7990ifneq ($(strip $(ADDITIONAL_PHP_PACKAGES ) ) ,)
@@ -157,16 +168,14 @@ localize:
157168info :
158169 $(info )
159170 $(info Containers for "$(COMPOSE_PROJECT_NAME ) " info:)
160- $(eval CONTAINERS = $(shell docker ps -f name=$(COMPOSE_PROJECT_NAME ) --format "{{ .ID }}" -f 'label=traefik.enable=true') )
161- $(foreach CONTAINER, $(CONTAINERS ) ,$(info http://$(shell printf '% -19s \n' $(shell docker inspect --format='{{(index .NetworkSettings.Networks "$(COMPOSE_NET_NAME ) ") .IPAddress}}:{{index .Config.Labels "traefik.port"}} {{range $$p, $$conf := .NetworkSettings.Ports}}{{$$p}}{{end}} {{.Name}}' $(CONTAINER ) | rev | sed "s/pct\//,pct:/g" | sed "s/,//" | rev | awk '{ print $0}') ) ) )
162171 $(info )
163172ifdef REVIEW_DOMAIN
164173 $(eval BASE_URL := $(MAIN_DOMAIN_NAME))
165174else
166- $(eval BASE_URL := $(shell docker inspect --format= '{{(index .NetworkSettings.Networks "$(COMPOSE_NET_NAME)").IPAddress}}:{{index .Config.Labels "traefik.port "}}' $(COMPOSE_PROJECT_NAME)_web ))
175+ $(eval BASE_URL := $(shell kubectl get pods -l name=sdc --template '{{range .items}}{{.status.podIP}}{{"\n "}}{{end}}' ))
167176endif
168- $(info Login as System Admin: http://$(shell printf '%-19s \n' $(shell echo "$(BASE_URL)"$(shell $(call php, drush user:login --name="$(ADMIN_NAME)" /admin/content/ | awk -F "default" '{print $$2}')))))
169- $(info Login as Contributor: http://$(shell printf '%-19s \n' $(shell echo "$(BASE_URL)"$(shell $(call php, drush user:login --name="$(TESTER_NAME)" /admin/content/ | awk -F "default" '{print $$2}')))))
177+ $(info Login as System Admin: http://$(shell printf '%-19s \n' $(shell echo "$(BASE_URL)"$(shell $(call php, drush user:login --name="$(ADMIN_NAME)" /admin/content/ | awk -F "default" '{print \ $$2}')))))
178+ $(info Login as Contributor: http://$(shell printf '%-19s \n' $(shell echo "$(BASE_URL)"$(shell $(call php, drush user:login --name="$(TESTER_NAME)" /admin/content/ | awk -F "default" '{print \ $$2}')))))
170179 $(info )
171180ifneq ($(shell diff .env .env.default -q) ,)
172181 @echo -e "\x1b[33mWARNING\x1b[0m - .env and .env.default files differ. Use 'make diff' to see details."
@@ -183,11 +192,11 @@ diff:
183192
184193# # Run shell in PHP container as regular user
185194exec :
186- docker-compose exec --user $( CUID ) : $( CGID ) php ash
195+ kubectl exec -it deploy/sdc -c php -- su -s /bin/ash www-data -c ash
187196
188197# # Run shell in PHP container as root
189198exec0 :
190- docker-compose exec --user 0:0 php ash
199+ kubectl exec -it deploy/sdc -c php -- ash
191200
192201down :
193202 @echo " Removing network & containers for $( COMPOSE_PROJECT_NAME) "
232241drush :
233242 $(call php, $(filter-out "$@ ",$(MAKECMDGOALS ) ) )
234243 $(info "To pass arguments use double dash: "make drush en devel -- -y"")
244+
245+ logs :
246+ kubectl logs -f deploy/sdc --all-containers=true
0 commit comments