diff --git a/.gitignore b/.gitignore index 3cc4a24c..13a4a0ab 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /.vagrant /.idea +/.composer /log/*.log /scripts/.current_nesting_level /scripts/.current_log_path diff --git a/README.md b/README.md index 31ae3497..d139f841 100755 --- a/README.md +++ b/README.md @@ -378,3 +378,15 @@ Note: See [Working with npm](https://www.npmjs.com/package/n#working-with-npm) i mv ~/.vagrant.d/boxes/{name of your paliarush/ubuntu image}/metadata_url2 ~/.vagrant.d/boxes/{name of your paliarush/ubuntu image}/metadata_url ``` +# Kubernetes + +Install helm: +`brew install kubernetes-helm` - see [installation guide](https://docs.helm.sh/using_helm/#installing-helm) + +Install helm client with `helm init` + +To get Helm support in PhpStorm make sure to get v2018.3+ + +## Manual steps (workarounds) +1. `sudo chmod a+w .` needed to allow write permissions over NFS since users are different on the guest and host +2. `chmod a+x magento/bin/magento` diff --git a/etc/.gitignore b/etc/.gitignore index 44c9e130..28043b96 100644 --- a/etc/.gitignore +++ b/etc/.gitignore @@ -1,8 +1,11 @@ /* !/.gitignore +!/docker !/composer /composer/* !/composer/auth.json.dist !/config.yaml.dist !/magento2_virtual_host.conf.dist -!/guest \ No newline at end of file +!/guest +!/kubernetes +!/helm diff --git a/etc/config.yaml.dist b/etc/config.yaml.dist index b9b582c2..ac836ce2 100644 --- a/etc/config.yaml.dist +++ b/etc/config.yaml.dist @@ -41,8 +41,6 @@ environment: use_varnish: 0 # [To apply changes: m-reinstall] Possible values: mysql, elasticsearch search_engine: "mysql" - # [To apply changes: m-clear-cache] Possible values: redis, filesystem - cache_backend: "redis" magento: # [To apply changes: m-switch-to-ce -f OR m-switch-to-ee -f] diff --git a/etc/docker/monolith-with-xdebug/Dockerfile b/etc/docker/monolith-with-xdebug/Dockerfile new file mode 100755 index 00000000..757adc3e --- /dev/null +++ b/etc/docker/monolith-with-xdebug/Dockerfile @@ -0,0 +1,4 @@ +FROM magento2-monolith:dev + +RUN sed -i "s|;zend_extension=xdebug.so|zend_extension=xdebug.so|g" /usr/local/etc/php/conf.d/zz-xdebug-settings.ini +RUN sed -i "s|listen = 0.0.0.0:9001|listen = 0.0.0.0:9002|g" /usr/local/etc/php-fpm.conf diff --git a/etc/docker/monolith/Dockerfile b/etc/docker/monolith/Dockerfile new file mode 100755 index 00000000..49e1e54d --- /dev/null +++ b/etc/docker/monolith/Dockerfile @@ -0,0 +1,3 @@ +FROM paliarush123/minikube-php-fpm:latest + +RUN sed -i "s|listen = 0.0.0.0:9000|listen = 0.0.0.0:9001|g" /usr/local/etc/php-fpm.conf diff --git a/etc/helm/.gitignore b/etc/helm/.gitignore new file mode 100644 index 00000000..ed599517 --- /dev/null +++ b/etc/helm/.gitignore @@ -0,0 +1,12 @@ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ +charts/checkout/sources/* +sources/ diff --git a/etc/helm/.helmignore b/etc/helm/.helmignore new file mode 100644 index 00000000..50af0317 --- /dev/null +++ b/etc/helm/.helmignore @@ -0,0 +1,22 @@ +# 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 +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/etc/helm/Chart.yaml b/etc/helm/Chart.yaml new file mode 100644 index 00000000..b7b0356e --- /dev/null +++ b/etc/helm/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: monolith +version: 0.1.0 diff --git a/etc/helm/LICENSE_MIT b/etc/helm/LICENSE_MIT new file mode 100644 index 00000000..017c0cdf --- /dev/null +++ b/etc/helm/LICENSE_MIT @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2019 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/etc/helm/README.md b/etc/helm/README.md new file mode 100644 index 00000000..059c719c --- /dev/null +++ b/etc/helm/README.md @@ -0,0 +1,75 @@ +# Magento Kubernetes components + +Install minikube. + +Start minikube. And use docker env. + +```bash +minikube start +eval $(minikube docker-env) +``` + +Install helm (cluster should be run to set tiller). [Install guide](https://docs.helm.sh/using_helm/#installing-helm) + + +## NFS server (optional) + +Configure your sources directory as export (/etc/exports) in the NFS server that runs on your host machine. This way containers can mount source code. This is a lot faster than a default VirtualBox shared folder mount. You only have to do this once, the NFS service will load /etc/exports at (re)boot. + +NOTE: The Minikube IP can be different after a minikube delete and minikube start command. Make sure that your NFS export contains the correct Minikube IP again. + +[More info](http://pietervogelaar.nl/minikube-nfs-mounts) + +### Mac OS X +If you do not have python, install it using brew: +```bash +brew install python +``` +echo "$(python -c 'import os,sys;print(os.path.realpath(".")')/sources -alldirs -mapall="$(id -u)":"$(id -g))" $(minikube ip)" | sudo tee -a /etc/exports && sudo nfsd restart +Check if the entry is active by executing on your host machine: + +```bash +showmount -e 127.0.0.1 +``` + +This should output something like: + +```bash +Exports list on 127.0.0.1: +/Absolute/path/to/magento 192.168.99.100 +``` + +There is also variable in values.yml which should be enabled + +## Run deployments + +Configuration values located in values.yaml + +To run all charts execute next command: + +```bash +helm install --values values.yaml . +``` + +(temporary) Magento sources should be cloned to source path in current chart and in checkout subchart as well. + +DB password autogenerated in container, to check it list pods: +```bash +kubectl get pods +``` + +choose one of mysql pods end run bash in it: + +```bash +kubectl exec -it release-1-some-mysql-pod bash +``` + +Observe env variables with prefix MYSQL_ + +## Clean + +To delete releases run: +``` +helm delete $(helm list -q) +``` + diff --git a/etc/helm/charts/checkout/Chart.yaml b/etc/helm/charts/checkout/Chart.yaml new file mode 100644 index 00000000..3c82960b --- /dev/null +++ b/etc/helm/charts/checkout/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: checkout +version: 0.1.0 diff --git a/etc/helm/charts/checkout/charts/mysql-0.9.2.tgz b/etc/helm/charts/checkout/charts/mysql-0.9.2.tgz new file mode 100644 index 00000000..21054c1f Binary files /dev/null and b/etc/helm/charts/checkout/charts/mysql-0.9.2.tgz differ diff --git a/etc/helm/charts/checkout/etc/nginx.conf b/etc/helm/charts/checkout/etc/nginx.conf new file mode 100644 index 00000000..887c612d --- /dev/null +++ b/etc/helm/charts/checkout/etc/nginx.conf @@ -0,0 +1,23 @@ +events { + worker_connections 1024; +} + +http { + include mime.types; + default_type application/octet-stream; + sendfile on; + keepalive_timeout 65; + + upstream fastcgi_backend { + server 127.0.0.1:9000; + } + + server { + listen 80 default_server; + listen [::]:80 default_server; + + server_name _; + set $MAGE_ROOT {{.Values.global.checkout.volumeHostPath}}; + include {{.Values.global.checkout.volumeHostPath}}/nginx.conf.sample; + } +} diff --git a/etc/helm/charts/checkout/requirements.lock b/etc/helm/charts/checkout/requirements.lock new file mode 100644 index 00000000..fec95390 --- /dev/null +++ b/etc/helm/charts/checkout/requirements.lock @@ -0,0 +1,6 @@ +dependencies: +- name: mysql + repository: https://kubernetes-charts.storage.googleapis.com/ + version: 0.9.2 +digest: sha256:5f1ec2d74a44651865b038da4fb76dc9d5ee04084a1db574c50657ba1b0d96fc +generated: 2019-01-03T00:55:37.077265-08:00 diff --git a/etc/helm/charts/checkout/requirements.yaml b/etc/helm/charts/checkout/requirements.yaml new file mode 100644 index 00000000..9a65218c --- /dev/null +++ b/etc/helm/charts/checkout/requirements.yaml @@ -0,0 +1,6 @@ +dependencies: +- name: mysql + version: "0.9.2" + appVersion: 5.7.14 + repository: "@stable" + alias: checkout-mysql \ No newline at end of file diff --git a/etc/helm/charts/checkout/templates/_helpers.tpl b/etc/helm/charts/checkout/templates/_helpers.tpl new file mode 100644 index 00000000..a9c9c718 --- /dev/null +++ b/etc/helm/charts/checkout/templates/_helpers.tpl @@ -0,0 +1,32 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "checkout.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 "checkout.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 "checkout.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/etc/helm/charts/checkout/templates/checkout-deployment.yaml b/etc/helm/charts/checkout/templates/checkout-deployment.yaml new file mode 100644 index 00000000..533fce7c --- /dev/null +++ b/etc/helm/charts/checkout/templates/checkout-deployment.yaml @@ -0,0 +1,49 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "checkout.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "checkout.name" . }} + helm.sh/chart: {{ include "checkout.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + selector: + matchLabels: + app.kubernetes.io/name: {{ include "checkout.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "checkout.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - containerPort: 80 + volumeMounts: + - name: {{ .Chart.Name }}-code + mountPath: {{.Values.global.checkout.volumeHostPath}} + - name: {{ .Chart.Name }}-nginx + image: nginx:1.9 + volumeMounts: + - name: {{ .Chart.Name }}-code + mountPath: {{.Values.global.checkout.volumeHostPath}} + - name: {{ template "checkout.fullname" . }}-nginx-config-volume + mountPath: /etc/nginx/nginx.conf + subPath: nginx.conf + volumes: + - name: {{ template "checkout.fullname" . }}-nginx-config-volume + configMap: + name: {{ template "checkout.fullname" . }}-nginx-config + - name: {{ .Chart.Name }}-code + {{- if .Values.persistence.nfs.enabled }} + persistentVolumeClaim: + claimName: {{ include "checkout.fullname" . }}-claim + {{- else }} + hostPath: + path: {{.Values.global.checkout.volumeHostPath}} + {{- end -}} diff --git a/etc/helm/charts/checkout/templates/configmap.yaml b/etc/helm/charts/checkout/templates/configmap.yaml new file mode 100644 index 00000000..e9a48281 --- /dev/null +++ b/etc/helm/charts/checkout/templates/configmap.yaml @@ -0,0 +1,6 @@ +kind: ConfigMap +apiVersion: v1 +metadata: + name: {{ template "checkout.fullname" . }}-nginx-config +data: + nginx.conf: {{.Files.Get "etc/nginx.conf" | printf "%s" | indent 4}} \ No newline at end of file diff --git a/etc/helm/charts/checkout/templates/default-sources-volume-claim.yaml b/etc/helm/charts/checkout/templates/default-sources-volume-claim.yaml new file mode 100644 index 00000000..5d620593 --- /dev/null +++ b/etc/helm/charts/checkout/templates/default-sources-volume-claim.yaml @@ -0,0 +1,14 @@ +{{- if .Values.persistence.nfs.enabled }} +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: {{ include "checkout.fullname" . }}-claim + namespace: default +spec: + storageClassName: standard + accessModes: + - ReadWriteMany + resources: + requests: + storage: 2Gi +{{- end }} \ No newline at end of file diff --git a/etc/helm/charts/checkout/templates/default-sources-volume.yaml b/etc/helm/charts/checkout/templates/default-sources-volume.yaml new file mode 100644 index 00000000..f1b95f4a --- /dev/null +++ b/etc/helm/charts/checkout/templates/default-sources-volume.yaml @@ -0,0 +1,19 @@ +{{- if .Values.persistence.nfs.enabled }} +apiVersion: v1 +kind: PersistentVolume +metadata: + name: {{ include "checkout.fullname" . }}-volume +spec: + capacity: + storage: 2Gi + accessModes: + - ReadWriteMany + storageClassName: standard + nfs: + # The address 192.168.99.1 is the Minikube gateway to the host. This way + # not the container IP will be visible by the NFS server on the host machine, + # but the IP address of the `minikube ip` command. You will need to + # grant access to the `minikube ip` IP address. + server: 192.168.99.1 + path: {{.Values.global.checkout.volumeHostPath}} +{{- end }} diff --git a/etc/helm/charts/checkout/values.yaml b/etc/helm/charts/checkout/values.yaml new file mode 100644 index 00000000..f046e25f --- /dev/null +++ b/etc/helm/charts/checkout/values.yaml @@ -0,0 +1,57 @@ +replicaCount: 1 + +image: + repository: shiftedreality/magento-kubernetes-components-php + tag: 7.1-fpm + pullPolicy: IfNotPresent + +nameOverride: "" +fullnameOverride: "" + +service: + type: NodePort + port: 80 + nodePort: 30102 + +persistence: + nfs: + enabled: true + +monolith: + volumeHostPath: /Users/user/Projects/magento2-kubernetes-for-developers + +checkout: + name: magento2-checkout + volumeHostPath: /Users/user/Projects/magento2-kubernetes-for-developers + service: + type: NodePort + ports: + nodePort: 30102 + port: 80 + deployment: + nginxImage: nginx:1.9 + codeImage: shiftedreality/magento-kubernetes-components-php + imageTag: 7.1-fpm + imagePullPolicy: Always + +resources: {} + # Uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +global: + chekout: + mysqlHost: checkout-mysql + volumeHostPath: /Users/user/Projects/magento2-kubernetes-for-developers + diff --git a/etc/helm/charts/mysql-0.9.2.tgz b/etc/helm/charts/mysql-0.9.2.tgz new file mode 100644 index 00000000..21054c1f Binary files /dev/null and b/etc/helm/charts/mysql-0.9.2.tgz differ diff --git a/etc/helm/charts/redis-5.0.0.tgz b/etc/helm/charts/redis-5.0.0.tgz new file mode 100644 index 00000000..30a27a25 Binary files /dev/null and b/etc/helm/charts/redis-5.0.0.tgz differ diff --git a/etc/helm/requirements.lock b/etc/helm/requirements.lock new file mode 100644 index 00000000..4853f23c --- /dev/null +++ b/etc/helm/requirements.lock @@ -0,0 +1,9 @@ +dependencies: +- name: mysql + repository: https://kubernetes-charts.storage.googleapis.com + version: 0.9.2 +- name: redis + repository: https://kubernetes-charts.storage.googleapis.com + version: 5.0.0 +digest: sha256:3c0e99a51b20812dfe0d407e8f4ee6ed1a9c2469bc2320d115e5fda0c538340b +generated: 2019-01-11T20:39:26.594816-06:00 diff --git a/etc/helm/requirements.yaml b/etc/helm/requirements.yaml new file mode 100644 index 00000000..fb36e1da --- /dev/null +++ b/etc/helm/requirements.yaml @@ -0,0 +1,12 @@ +dependencies: +- name: mysql + version: "0.9.2" + appVersion: 5.7.14 + repository: "@stable" +- name: redis + repository: "@stable" + version: "5.0" +#- name: checkout +# repository: http://localhost:10191 +# version: 0.1.0 +# condition: global.checkout.enabled diff --git a/etc/helm/templates/NOTES.txt b/etc/helm/templates/NOTES.txt new file mode 100644 index 00000000..cb226079 --- /dev/null +++ b/etc/helm/templates/NOTES.txt @@ -0,0 +1,11 @@ +1. Get the application URL by running these commands: +minikube service {{ include "magento.fullname" . }} + +Deployed database can by accessed by next hosts from inside network: +{{ .Release.Name }}-mysql + +2. Get the application URL by running these commands: + minikube service {{ .Release.Name }}-checkout +Deployed databases can by accessed by next hosts from inside networks: + +{{ .Release.Name }}-checkout-mysql \ No newline at end of file diff --git a/etc/helm/templates/_helpers.tpl b/etc/helm/templates/_helpers.tpl new file mode 100644 index 00000000..64c30fa6 --- /dev/null +++ b/etc/helm/templates/_helpers.tpl @@ -0,0 +1,32 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "magento.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 "magento.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 "magento.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/etc/helm/templates/configmap.yaml b/etc/helm/templates/configmap.yaml new file mode 100644 index 00000000..84aaf83f --- /dev/null +++ b/etc/helm/templates/configmap.yaml @@ -0,0 +1,215 @@ +kind: ConfigMap +apiVersion: v1 +metadata: + name: {{ template "magento.fullname" . }}-nginx-config +data: + nginx.conf: | + events { + worker_connections 1024; + } + + http { + include mime.types; + default_type application/octet-stream; + sendfile on; + keepalive_timeout 65; + client_max_body_size 200M; + gzip on; + fastcgi_read_timeout 30000s; + + upstream fastcgi_backend { + server 127.0.0.1:9001; + } + + upstream fastcgi_backend_xdebug { + server 127.0.0.1:9002; + } + + map $cookie_XDEBUG_SESSION $fastcgi_backend_name { + "" "fastcgi_backend"; + default "fastcgi_backend_xdebug"; + } + + server { + listen 8001; + + server_name _; + set $MAGE_ROOT {{.Values.global.monolith.volumeHostPath}}/magento; + root $MAGE_ROOT/pub; + + index index.php; + autoindex off; + charset UTF-8; + error_page 404 403 = /errors/404.php; + #add_header "X-UA-Compatible" "IE=Edge"; + + # PHP entry point for setup application + location ~* ^/setup($|/) { + root $MAGE_ROOT; + location ~ ^/setup/index.php { + fastcgi_pass fastcgi_backend; + + fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off"; + fastcgi_param PHP_VALUE "memory_limit=756M \n max_execution_time=600"; + fastcgi_read_timeout 600s; + fastcgi_connect_timeout 600s; + + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } + + location ~ ^/setup/(?!pub/). { + deny all; + } + + location ~ ^/setup/pub/ { + add_header X-Frame-Options "SAMEORIGIN"; + } + } + + # PHP entry point for update application + location ~* ^/update($|/) { + root $MAGE_ROOT; + + location ~ ^/update/index.php { + fastcgi_split_path_info ^(/update/index.php)(/.+)$; + fastcgi_pass fastcgi_backend; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + include fastcgi_params; + } + + # Deny everything but index.php + location ~ ^/update/(?!pub/). { + deny all; + } + + location ~ ^/update/pub/ { + add_header X-Frame-Options "SAMEORIGIN"; + } + } + + location / { + try_files $uri $uri/ /index.php$is_args$args; + } + + location /pub/ { + location ~ ^/pub/media/(downloadable|customer|import|theme_customization/.*\.xml) { + deny all; + } + alias $MAGE_ROOT/pub/; + add_header X-Frame-Options "SAMEORIGIN"; + } + + location /static/ { + # Uncomment the following line in production mode + # expires max; + + # Remove signature of the static files that is used to overcome the browser cache + location ~ ^/static/version { + rewrite ^/static/(version[^/]+/)?(.*)$ /static/$2 last; + } + + location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2|json)$ { + add_header Cache-Control "public"; + add_header X-Frame-Options "SAMEORIGIN"; + expires +1y; + + if (!-f $request_filename) { + rewrite ^/static/?(.*)$ /static.php?resource=$1 last; + } + } + location ~* \.(zip|gz|gzip|bz2|csv|xml)$ { + add_header Cache-Control "no-store"; + add_header X-Frame-Options "SAMEORIGIN"; + expires off; + + if (!-f $request_filename) { + rewrite ^/static/?(.*)$ /static.php?resource=$1 last; + } + } + if (!-f $request_filename) { + rewrite ^/static/?(.*)$ /static.php?resource=$1 last; + } + add_header X-Frame-Options "SAMEORIGIN"; + } + + location /media/ { + try_files $uri $uri/ /get.php$is_args$args; + + location ~ ^/media/theme_customization/.*\.xml { + deny all; + } + + location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ { + add_header Cache-Control "public"; + add_header X-Frame-Options "SAMEORIGIN"; + expires +1y; + try_files $uri $uri/ /get.php$is_args$args; + } + location ~* \.(zip|gz|gzip|bz2|csv|xml)$ { + add_header Cache-Control "no-store"; + add_header X-Frame-Options "SAMEORIGIN"; + expires off; + try_files $uri $uri/ /get.php$is_args$args; + } + add_header X-Frame-Options "SAMEORIGIN"; + } + + location /media/customer/ { + deny all; + } + + location /media/downloadable/ { + deny all; + } + + location /media/import/ { + deny all; + } + + # PHP entry point for main application + location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check)\.php$ { + try_files $uri =404; + fastcgi_pass $fastcgi_backend_name; + fastcgi_buffers 1024 4k; + + fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off"; + fastcgi_param PHP_VALUE "memory_limit=756M \n max_execution_time=18000"; + fastcgi_read_timeout 600s; + fastcgi_connect_timeout 600s; + + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } + + gzip on; + gzip_disable "msie6"; + + gzip_comp_level 6; + gzip_min_length 1100; + gzip_buffers 16 8k; + gzip_proxied any; + gzip_types + text/plain + text/css + text/js + text/xml + text/javascript + application/javascript + application/x-javascript + application/json + application/xml + application/xml+rss + image/svg+xml; + gzip_vary on; + + # Banned locations (only reached if the earlier PHP entry point regexes don't match) + location ~* (\.php$|\.htaccess$|\.git) { + deny all; + } + } + } diff --git a/etc/helm/templates/default-sources-volume-claim.yaml b/etc/helm/templates/default-sources-volume-claim.yaml new file mode 100644 index 00000000..e5dbb346 --- /dev/null +++ b/etc/helm/templates/default-sources-volume-claim.yaml @@ -0,0 +1,14 @@ +{{- if .Values.persistence.nfs.enabled }} +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: {{ include "magento.fullname" . }}-claim + namespace: default +spec: + storageClassName: standard + accessModes: + - ReadWriteMany + resources: + requests: + storage: 2Gi +{{- end }} \ No newline at end of file diff --git a/etc/helm/templates/default-sources-volume.yaml b/etc/helm/templates/default-sources-volume.yaml new file mode 100644 index 00000000..25b4a00a --- /dev/null +++ b/etc/helm/templates/default-sources-volume.yaml @@ -0,0 +1,19 @@ +{{- if .Values.persistence.nfs.enabled }} +apiVersion: v1 +kind: PersistentVolume +metadata: + name: {{ include "magento.fullname" . }}-volume +spec: + capacity: + storage: 2Gi + accessModes: + - ReadWriteMany + storageClassName: standard + nfs: + # The address 192.168.99.1 is the Minikube gateway to the host. This way + # not the container IP will be visible by the NFS server on the host machine, + # but the IP address of the `minikube ip` command. You will need to + # grant access to the `minikube ip` IP address. + server: 192.168.99.1 + path: {{.Values.global.monolith.volumeHostPath}} +{{- end }} diff --git a/etc/helm/templates/magento2-deployment.yaml b/etc/helm/templates/magento2-deployment.yaml new file mode 100644 index 00000000..6addc8bd --- /dev/null +++ b/etc/helm/templates/magento2-deployment.yaml @@ -0,0 +1,85 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "magento.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "magento.name" . }} + helm.sh/chart: {{ include "magento.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + selector: + matchLabels: + app.kubernetes.io/name: {{ include "magento.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + strategy: + type: Recreate + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "magento.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: magento2-monolith:dev + imagePullPolicy: Never + ports: + - containerPort: {{ .Values.service.port }} + volumeMounts: + - name: code + mountPath: {{.Values.global.monolith.volumeHostPath}} + env: + - name: VAGRANT_ROOT + value: {{.Values.global.monolith.volumeHostPath}} + - name: COMPOSER_HOME + value: {{.Values.global.monolith.volumeHostPath}}/.composer + - name: MAGENTO_ROOT + value: {{.Values.global.monolith.volumeHostPath}}/magento + - name: MAGENTO_ROOT_HOST + value: {{.Values.global.monolith.volumeHostPath}}/magento + - name: VAGRANT_ROOT_HOST + value: {{.Values.global.monolith.volumeHostPath}} + - name: IS_WINDOWS_HOST + value: "0" + - name: {{ .Chart.Name }}-xdebug + image: magento2-monolith:dev-xdebug + imagePullPolicy: Never + ports: + - containerPort: {{ .Values.xdebugService.port }} + volumeMounts: + - name: code + mountPath: {{.Values.global.monolith.volumeHostPath}} + env: + - name: VAGRANT_ROOT + value: {{.Values.global.monolith.volumeHostPath}} + - name: COMPOSER_HOME + value: {{.Values.global.monolith.volumeHostPath}}/.composer + - name: MAGENTO_ROOT + value: {{.Values.global.monolith.volumeHostPath}}/magento + - name: MAGENTO_ROOT_HOST + value: {{.Values.global.monolith.volumeHostPath}}/magento + - name: VAGRANT_ROOT_HOST + value: {{.Values.global.monolith.volumeHostPath}} + - name: IS_WINDOWS_HOST + value: "0" + - name: nginx + image: nginx:1.9 + volumeMounts: + - name: code + mountPath: {{.Values.global.monolith.volumeHostPath}} + - name: nginx-config-volume + mountPath: /etc/nginx/nginx.conf + subPath: nginx.conf + volumes: + - name: nginx-config-volume + configMap: + name: {{ template "magento.fullname" . }}-nginx-config + - name: code + {{- if .Values.persistence.nfs.enabled }} + persistentVolumeClaim: + claimName: {{ include "magento.fullname" . }}-claim + {{- else }} + hostPath: + path: {{.Values.global.monolith.volumeHostPath}} + {{- end -}} diff --git a/etc/helm/templates/proxy-deployment.yaml b/etc/helm/templates/proxy-deployment.yaml new file mode 100644 index 00000000..db0496d7 --- /dev/null +++ b/etc/helm/templates/proxy-deployment.yaml @@ -0,0 +1,28 @@ +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: magento-ingress + annotations: + kubernetes.io/ingress.class: "nginx" + kubernetes.io/ingress.allow-http: "true" + nginx.ingress.kubernetes.io/ssl-redirect: "false" + nginx.ingress.kubernetes.io/rewrite-target: / +spec: + rules: + - http: + paths: +# Monolith installation + - path: / + backend: + serviceName: {{ include "magento.fullname" . }} + servicePort: {{ .Values.service.port }} + +## Multi-service installation +# - path: /magento +# backend: +# serviceName: magento2 +# servicePort: 80 +# - path: /checkout +# backend: +# serviceName: magento2-checkout +# servicePort: 80 diff --git a/etc/helm/templates/service.yaml b/etc/helm/templates/service.yaml new file mode 100644 index 00000000..4d93c6ed --- /dev/null +++ b/etc/helm/templates/service.yaml @@ -0,0 +1,35 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "magento.fullname" . }} + labels: + app: {{ include "magento.name" . }} + app.kubernetes.io/name: {{ include "magento.name" . }} + helm.sh/chart: {{ include "magento.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + nodePort: {{ .Values.service.nodePort }} + selector: + app.kubernetes.io/name: {{ include "magento.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} +--- +apiVersion: v1 +kind: Service +metadata: + name: magento2-redis + labels: + app: redis + role: master + tier: backend +spec: + ports: + - port: 6379 + targetPort: 6379 + selector: + app: redis + role: master + tier: backend diff --git a/etc/helm/values.yaml b/etc/helm/values.yaml new file mode 100644 index 00000000..f01a9c79 --- /dev/null +++ b/etc/helm/values.yaml @@ -0,0 +1,67 @@ +replicaCount: 1 + +image: + repository: shiftedreality/magento-kubernetes-components-php + tag: 7.1-fpm + pullPolicy: IfNotPresent + +nameOverride: "" +fullnameOverride: "" + +service: + type: NodePort + port: 8001 + nodePort: 30301 + +xdebugService: + type: NodePort + port: 8002 + nodePort: 30302 + +persistence: + nfs: + enabled: true + +monolith: + name: magento2 + service: + type: NodePort + ports: + nodePort: 30301 + port: 8001 + deployment: + nginxImage: nginx:1.9 + codeImage: shiftedreality/magento-kubernetes-components-php + imageTag: 7.1-fpm + imagePullPolicy: Always +global: + monolith: + mysqlHost: magento-mysql + volumeHostPath: /Users/user/Projects/magento2-kubernetes-for-developers + +checkout: + enabled: false +resources: {} + # Uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +mysql: + fullname: magento-mysql + mysqlRootPassword: "1234" + +redis: + usePassword: false + master: + disableCommands: [] diff --git a/init_project.sh b/init_project.sh index fab1c215..515697ab 100755 --- a/init_project.sh +++ b/init_project.sh @@ -1,10 +1,11 @@ #!/usr/bin/env bash +## TODO: Fix set -e vagrant_dir=$PWD -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" resetNestingLevel current_script_name=`basename "$0"` initLogFile ${current_script_name} @@ -20,7 +21,7 @@ if [[ ! -f "${config_path}" ]]; then cp "${config_path}.dist" "${config_path}" fi -magento_ce_dir="${vagrant_dir}/magento2ce" +magento_ce_dir="${vagrant_dir}/magento" magento_ce_sample_data_dir="${magento_ce_dir}/magento2ce-sample-data" magento_ee_dir="${magento_ce_dir}/magento2ee" magento_ee_sample_data_dir="${magento_ce_dir}/magento2ee-sample-data" @@ -145,26 +146,6 @@ function composerCreateProject() bash "${vagrant_dir}/scripts/host/check_requirements.sh" -status "Installing missing vagrant plugins" -vagrant_plugin_list="$(vagrant plugin list)" -if ! echo ${vagrant_plugin_list} | grep -q 'vagrant-hostmanager' ; then - vagrant plugin install vagrant-hostmanager -fi -if ! echo ${vagrant_plugin_list} | grep -q 'vagrant-vbguest' ; then - vagrant plugin install vagrant-vbguest -fi -if ! echo ${vagrant_plugin_list} | grep -q 'vagrant-host-shell' ; then - vagrant plugin install vagrant-host-shell -fi - -status "Generating random IP address, and host name to prevent collisions (if no custom values specified)" -random_ip="$(( ( RANDOM % 240 ) + 12 ))" -forwarded_ssh_port="$(( random_ip + 3000 ))" -sed -i.back "s|ip_address: \"192.168.10.2\"|ip_address: \"192.168.10.${random_ip}\"|g" "${config_path}" -sed -i.back "s|host_name: \"magento2.vagrant2\"|host_name: \"magento2.vagrant${random_ip}\"|g" "${config_path}" -sed -i.back "s|forwarded_ssh_port: 3000|forwarded_ssh_port: ${forwarded_ssh_port}|g" "${config_path}" -rm -f "${config_path}.back" - # Clean up the project before initialization if "-f" option was specified. Remove codebase if "-fc" is used. force_project_cleaning=0 force_codebase_cleaning=0 @@ -179,7 +160,28 @@ while getopts 'fcp' flag; do done if [[ ${force_project_cleaning} -eq 1 ]]; then status "Cleaning up the project before initialization since '-f' option was used" - vagrant destroy -f 2> >(logError) > >(log) + + if [[ $(isMinikubeRunning) -eq 1 ]]; then + minikube stop 2> >(logError) | { + while IFS= read -r line + do + filterVagrantOutput "${line}" + lastline="${line}" + done + filterVagrantOutput "${lastline}" + } + fi + if [[ $(isMinikubeStopped) -eq 1 ]]; then + minikube delete 2> >(logError) | { + while IFS= read -r line + do + filterVagrantOutput "${line}" + lastline="${line}" + done + filterVagrantOutput "${lastline}" + } + fi + mv "${vagrant_dir}/etc/guest/.gitignore" "${vagrant_dir}/etc/.gitignore.back" rm -rf "${vagrant_dir}/.vagrant" "${vagrant_dir}/etc/guest" mkdir "${vagrant_dir}/etc/guest" @@ -202,16 +204,19 @@ if [[ ! -d ${magento_ce_dir} ]]; then fi fi -if [[ "${checkout_source_from}" == "git" ]]; then - status "Installing Magento dependencies via Composer" - cd "${magento_ce_dir}" - bash "${vagrant_dir}/scripts/host/composer.sh" install -fi - -status "Initializing vagrant box" +status "Initializing dev box" cd "${vagrant_dir}" -vagrant up --provider virtualbox 2> >(logError) | { +if [[ $(isMinikubeInitialized) -eq 1 ]]; then + warning "The project has already been initialized. + To re-initialize the project add the '-f' flag (using just '-f' will not affect Magento codebase or PHP Storm settings). + To delete Magento codebase and initialize it from scratch based on etc/config.yaml add '-c' flag. + To reconfigure PHP Storm add '-p' flag." + exit 0 +fi + +status "Starting minikube" +minikube start --cpus=2 --memory=4096 2> >(logError) | { while IFS= read -r line do filterVagrantOutput "${line}" @@ -219,6 +224,17 @@ vagrant up --provider virtualbox 2> >(logError) | { done filterVagrantOutput "${lastline}" } +status "Configuring kubernetes cluster on the minikube" +# TODO: Optimize. Helm tiller must be initialized and started before environment configuration can begin +helm init && sleep 10 +# TODO: change k-rebuild-environment to comply with formatting requirements +bash "${vagrant_dir}/k-rebuild-environment" + +minikube_ip="$(minikube service magento2-monolith --url | grep -oE '[0-9][^:]+' | head -1)" +status "Saving minikube IP to etc/config.yaml (${minikube_ip})" +sed -i.back "s|ip_address: \".*\"|ip_address: \"${minikube_ip}\"|g" "${config_path}" +sed -i.back "s|host_name: \".*\"|host_name: \"${minikube_ip}\"|g" "${config_path}" +rm -f "${config_path}.back" bash "${vagrant_dir}/scripts/host/check_mounted_directories.sh" diff --git a/k-rebuild-environment b/k-rebuild-environment new file mode 100755 index 00000000..8aab37a6 --- /dev/null +++ b/k-rebuild-environment @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD + +source "${vagrant_dir}/scripts/functions.sh" +resetNestingLevel + + +## TODO: Add status messages +cd "${vagrant_dir}/scripts" && eval $(minikube docker-env) && docker build -t magento2-monolith:dev -f ../etc/docker/monolith/Dockerfile ../scripts +cd "${vagrant_dir}/scripts" && eval $(minikube docker-env) && docker build -t magento2-monolith:dev-xdebug -f ../etc/docker/monolith-with-xdebug/Dockerfile ../scripts + +# TODO: Repeat for other deployments, not just Magento 2 +# See https://github.com/kubernetes/kubernetes/issues/33664#issuecomment-386661882 + + +# TODO: Delete does not work when no releases created yet +cd "${vagrant_dir}/etc/helm" +helm list -q | xargs helm delete +set +e && helm del --purge magento2 && set -e + +# TODO: Need to make sure all resources have been successfully deleted before the attempt of recreating them +sleep 7 + +cd "${vagrant_dir}/etc/helm" && helm install \ + --name magento2 \ + --values values.yaml \ + --set global.monolith.volumeHostPath="${vagrant_dir}" \ + --set global.checkout.volumeHostPath="${vagrant_dir}" . + + +## Bypass Helm +#cd "${vagrant_dir}" && python local_deploy.py --all --ingress \ +# && kubectl patch deployment magento2-monolith -p \ +# "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"`date +'%s'`\"}}}}}" + +info "$(regular)See details in $(bold)${vagrant_dir}/log/${current_script_name}.log$(regular). For debug output set $(bold)debug:vagrant_project$(regular) to $(bold)1$(regular) in $(bold)etc/config.yaml$(regular)" diff --git a/k-restart b/k-restart new file mode 100755 index 00000000..6fac97ba --- /dev/null +++ b/k-restart @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD + +source "${vagrant_dir}/scripts/functions.sh" +resetNestingLevel + +if [[ $(isMinikubeRunning) -eq 1 ]]; then + minikube stop 2> >(logError) +fi + +minikube start --cpus=2 --memory=4096 2> >(logError) + +info "$(regular)See details in $(bold)${vagrant_dir}/log/${current_script_name}.log$(regular). For debug output set $(bold)debug:vagrant_project$(regular) to $(bold)1$(regular) in $(bold)etc/config.yaml$(regular)" diff --git a/k-ssh-magento2 b/k-ssh-magento2 new file mode 100755 index 00000000..261ffe65 --- /dev/null +++ b/k-ssh-magento2 @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD + +source "${vagrant_dir}/scripts/functions.sh" + +kubectl exec -it "$(getMagento2PodId)" --container monolith -- /bin/bash diff --git a/k-ssh-mysql b/k-ssh-mysql new file mode 100755 index 00000000..953cc7d2 --- /dev/null +++ b/k-ssh-mysql @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD + +source "${vagrant_dir}/scripts/functions.sh" + +kubectl exec -it "$(getMysqlPodId)" --container magento2-mysql -- /bin/bash diff --git a/k-ssh-nginx b/k-ssh-nginx new file mode 100755 index 00000000..199035d9 --- /dev/null +++ b/k-ssh-nginx @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD + +source "${vagrant_dir}/scripts/functions.sh" + +kubectl exec -it "$(getMagento2PodId)" --container nginx -- /bin/bash diff --git a/k-ssh-redis b/k-ssh-redis new file mode 100755 index 00000000..f4dac717 --- /dev/null +++ b/k-ssh-redis @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD + +source "${vagrant_dir}/scripts/functions.sh" + +kubectl exec -it "$(getRedisMasterPodId)" --container magento2-redis -- /bin/bash diff --git a/k-status b/k-status new file mode 100755 index 00000000..1f8f7137 --- /dev/null +++ b/k-status @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD + +source "${vagrant_dir}/scripts/functions.sh" +resetNestingLevel + +minikube dashboard & + +info "$(regular)See details in $(bold)${vagrant_dir}/log/${current_script_name}.log$(regular). For debug output set $(bold)debug:vagrant_project$(regular) to $(bold)1$(regular) in $(bold)etc/config.yaml$(regular)" diff --git a/local_deploy.py b/local_deploy.py new file mode 100644 index 00000000..e1976a0d --- /dev/null +++ b/local_deploy.py @@ -0,0 +1,31 @@ +import os +import sys +import argparse + +config_path = os.path.dirname(os.path.abspath(__file__)) + "/etc/kubernetes/" + + +def kubectl_build_command(config_name): + return 'cat ' + resolve_config(config_name) + ' | sed "s#{{PWD}}#$PWD#g" | sed "s#{{MINIKUBE_IP}}#$(minikube ip)#g" | kubectl apply -f -' + + +def resolve_config(config_name): + filename = config_name if config_name.endswith(".yaml") else config_name + ".yaml" + return config_path + filename + + +ingress = "kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml" +parser = argparse.ArgumentParser(description='Configuration file names.') +parser.add_argument('configs', type=str, nargs='*') +parser.add_argument('--all', action='store_true') +parser.add_argument('--ingress', action='store_true') +args = parser.parse_args() +if args.all: + args.configs = [filename for filename in os.listdir(config_path) if filename.endswith(".yaml")] + +commands = [kubectl_build_command(name) for name in args.configs if os.path.exists(resolve_config(name))] + +if args.ingress: + commands.append(ingress) + +map(os.system, commands) diff --git a/m-bin-magento b/m-bin-magento index 3d95fc2d..e99b74d1 100755 --- a/m-bin-magento +++ b/m-bin-magento @@ -4,7 +4,7 @@ set -e cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" resetNestingLevel current_script_name=`basename "$0"` initLogFile ${current_script_name} @@ -16,7 +16,7 @@ fi arguments=$@ cd "${vagrant_dir}" -vagrant ssh -c "\$MAGENTO_ROOT/bin/magento $arguments" 2> >(logError) +executeInMagento2Container php -- "${vagrant_dir}/magento/bin/magento" ${arguments} 2> >(logError) # To debug, comment out line above and uncomment line below # vagrant ssh -c "php -d xdebug.remote_autostart=1 \$MAGENTO_ROOT/bin/magento $arguments" 2> >(logError) diff --git a/m-clear-cache b/m-clear-cache index 18549cd6..fe65fb3d 100755 --- a/m-clear-cache +++ b/m-clear-cache @@ -4,7 +4,7 @@ set -e cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" resetNestingLevel current_script_name=`basename "$0"` initLogFile ${current_script_name} diff --git a/m-composer b/m-composer index 34251a58..37c1a71f 100755 --- a/m-composer +++ b/m-composer @@ -4,7 +4,7 @@ set -e cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" resetNestingLevel current_script_name=`basename "$0"` initLogFile ${current_script_name} diff --git a/m-open b/m-open new file mode 100755 index 00000000..f16fcb0d --- /dev/null +++ b/m-open @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD + +source "${vagrant_dir}/scripts/functions.sh" + +magento2_url_with_port80="$(minikube service magento2-monolith --url | grep -oE 'http:[^:]+'):80" +open ${magento2_url_with_port80} diff --git a/m-reinstall b/m-reinstall index b5a4c754..9edfcc6f 100755 --- a/m-reinstall +++ b/m-reinstall @@ -4,7 +4,7 @@ set -e cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" resetNestingLevel current_script_name=`basename "$0"` initLogFile ${current_script_name} diff --git a/m-search-engine b/m-search-engine index 58d955d6..6a7da34c 100755 --- a/m-search-engine +++ b/m-search-engine @@ -4,7 +4,7 @@ set -e cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" resetNestingLevel current_script_name=`basename "$0"` initLogFile ${current_script_name} diff --git a/m-switch-to-ce b/m-switch-to-ce index 9aeb7668..ff59eead 100755 --- a/m-switch-to-ce +++ b/m-switch-to-ce @@ -4,7 +4,7 @@ set -e cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" resetNestingLevel current_script_name=`basename "$0"` initLogFile ${current_script_name} diff --git a/m-switch-to-ee b/m-switch-to-ee index 83e192d8..e1e67b8e 100755 --- a/m-switch-to-ee +++ b/m-switch-to-ee @@ -4,7 +4,7 @@ set -e cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" resetNestingLevel current_script_name=`basename "$0"` initLogFile ${current_script_name} diff --git a/m-varnish b/m-varnish index a2e2b797..845960b9 100755 --- a/m-varnish +++ b/m-varnish @@ -4,7 +4,7 @@ set -e cd "$(dirname "${BASH_SOURCE[0]}")" && vagrant_dir=$PWD -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" resetNestingLevel current_script_name=`basename "$0"` initLogFile ${current_script_name} diff --git a/scripts/Dockerfile b/scripts/Dockerfile new file mode 100755 index 00000000..98b34350 --- /dev/null +++ b/scripts/Dockerfile @@ -0,0 +1,51 @@ +FROM php:7.1-fpm + +# Install dependencies +RUN apt-get update \ + && apt-get install -y \ + libfreetype6-dev \ + libicu-dev \ + libjpeg62-turbo-dev \ + libmcrypt-dev \ + libpng-dev \ + libxslt1-dev \ + sendmail-bin \ + sendmail \ + sudo \ + net-tools \ + nano + +# Configure the gd library +RUN docker-php-ext-configure \ + gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ + +RUN docker-php-ext-configure opcache --enable-opcache + +# Install required PHP extensions +RUN docker-php-ext-install \ + dom \ + gd \ + intl \ + mbstring \ + mcrypt \ + pdo_mysql \ + xsl \ + zip \ + bcmath \ + soap \ + opcache + +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer +RUN pecl install -o -f xdebug + +RUN apt-get update && apt-get install -y mysql-client && rm -rf /var/lib/apt/lists/* + +RUN apt-get update && apt-get install -y wget && rm -rf /var/lib/apt/lists/* + +RUN apt-get update && apt-get install -y redis-tools && rm -rf /var/lib/apt/lists/* + +COPY etc/php-xdebug.ini /usr/local/etc/php/conf.d/zz-xdebug-settings.ini +COPY etc/php-fpm.ini /usr/local/etc/php/conf.d/zz-magento.ini +COPY etc/php-fpm.conf /usr/local/etc/ + +CMD ["php-fpm", "-R"] diff --git a/scripts/colors.sh b/scripts/colors.sh old mode 100644 new mode 100755 diff --git a/scripts/etc/php-fpm.conf b/scripts/etc/php-fpm.conf new file mode 100644 index 00000000..673a8091 --- /dev/null +++ b/scripts/etc/php-fpm.conf @@ -0,0 +1,13 @@ +[global] +error_log = /proc/self/fd/2 +daemonize = no + +[www] +access.log = /proc/self/fd/2 +clear_env = no +catch_workers_output = yes +user = root +group = root +listen = 0.0.0.0:9000 +pm = static +pm.max_children = 4 diff --git a/scripts/etc/php-fpm.ini b/scripts/etc/php-fpm.ini new file mode 100644 index 00000000..b119d7be --- /dev/null +++ b/scripts/etc/php-fpm.ini @@ -0,0 +1,29 @@ +; Basic configuration override +expose_php = off +memory_limit = 2047M +post_max_size = 128M +upload_max_filesize = 128M +date.timezone = UTC +max_execution_time = 18000 +session.auto_start = off +zlib.output_compression = on +sohosin.session.cryptua = off +always_populate_raw_post_data = -1 +session.save_path = /tmp +max_input_vars = 5000000 + +; Error reporting +display_errors = off +display_startup_errors = off +error_reporting = E_ALL +log_errors = on +error_log = /proc/self/fd/2 +opcache.error_log = /proc/self/fd/2 + +; A bit of performance tuning +realpath_cache_size = 128k + +; OpCache tuning +opcache.enable=1 +opcache.max_accelerated_files = 32000 +opcache.enable_cli = 1 diff --git a/scripts/etc/php-xdebug.ini b/scripts/etc/php-xdebug.ini new file mode 100644 index 00000000..9c94ab51 --- /dev/null +++ b/scripts/etc/php-xdebug.ini @@ -0,0 +1,6 @@ +;zend_extension=xdebug.so +xdebug.remote_enable = 1 +xdebug.remote_connect_back = 1 +xdebug.remote_port = 9000 +xdebug.remote_autostart=1 +xdebug.idekey = PHPSTORM diff --git a/scripts/output_functions.sh b/scripts/functions.sh old mode 100644 new mode 100755 similarity index 79% rename from scripts/output_functions.sh rename to scripts/functions.sh index cb5ad9c7..d5de6850 --- a/scripts/output_functions.sh +++ b/scripts/functions.sh @@ -59,7 +59,7 @@ function log() { else log_file="${default_log}" fi - echo "${input}" | sed "s/\[[[:digit:]]\{1,\}m//g" >> "${log_file}" + echo "${input}" | sed "s/\[[[:digit:]]\{1,\}m//g" >> "${log_file}" 2> /dev/null fi } @@ -114,6 +114,7 @@ function incrementNestingLevel() { if [[ ! -f "${nesting_level_file}" ]]; then echo 1 > "${nesting_level_file}" + chmod a+w "${nesting_level_file}" else nesting_level="$(cat "${nesting_level_file}")" nesting_level="$((${nesting_level}+1))" @@ -148,6 +149,8 @@ function initLogFile() fi echo "log/${log_file}.log" > "${log_file_path}" rm -f "${vagrant_dir}/log/${log_file}.log" + touch "${vagrant_dir}/log/${log_file}.log" + chmod a+w "${vagrant_dir}/log/${log_file}.log" } function getIndentationByNesting() @@ -183,3 +186,46 @@ function bash() { $(which bash) "$@" 2> >(logError) } + +# TODO: Move kubectl related functions to the host-only scripts +function getMagento2PodId() +{ + # TODO: Calculate based on current helm release + echo "$(kubectl get pods | grep -ohE 'magento2-monolith-[a-z0-9\-]+')" +} + +function getRedisMasterPodId() +{ + echo "$(kubectl get pods | grep -ohE 'magento2-redis-master-[a-z0-9\-]+')" +} + +function getMysqlPodId() +{ + echo "$(kubectl get pods | grep -ohE 'magento2-mysql-[a-z0-9\-]+')" +} + +function executeInMagento2Container() +{ + magento2_pod_id="$(getMagento2PodId)" + kubectl exec "${magento2_pod_id}" --container monolith "$@" 2> >(logError) +} + +function isMinikubeRunning() { + minikube_status="$(minikube status | grep minikube: 2> >(log))" + if [[ ${minikube_status} == "minikube: Running" ]]; then + echo 1 + fi +} + +function isMinikubeStopped() { + minikube_status="$(minikube status | grep minikube: 2> >(log))" + if [[ ${minikube_status} == "minikube: Stopped" ]]; then + echo 1 + fi +} + +function isMinikubeInitialized() { + if [[ $(isMinikubeRunning) -eq 1 || $(isMinikubeStopped) -eq 1 ]]; then + echo 1 + fi +} diff --git a/scripts/get_config_value.sh b/scripts/get_config_value.sh old mode 100644 new mode 100755 diff --git a/scripts/guest/change_magento_config_for_functional_tests b/scripts/guest/change_magento_config_for_functional_tests index 0b68188d..e9105c11 100755 --- a/scripts/guest/change_magento_config_for_functional_tests +++ b/scripts/guest/change_magento_config_for_functional_tests @@ -1,14 +1,14 @@ #!/usr/bin/env bash -vagrant_dir="/vagrant" +vagrant_dir="${VAGRANT_ROOT}" -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" status "Changing Magento configuration to allow execution of functional tests" incrementNestingLevel -update_magento_config 'cms/wysiwyg/enabled' 'disabled' -update_magento_config 'admin/security/admin_account_sharing' '1' -update_magento_config 'admin/security/use_form_key' '0' +"${VAGRANT_ROOT}/scripts/guest/update_magento_config" 'cms/wysiwyg/enabled' 'disabled' +"${VAGRANT_ROOT}/scripts/guest/update_magento_config" 'admin/security/admin_account_sharing' '1' +"${VAGRANT_ROOT}/scripts/guest/update_magento_config" 'admin/security/use_form_key' '0' decrementNestingLevel diff --git a/scripts/guest/check_mounted_directories b/scripts/guest/check_mounted_directories index 63f7473b..b97e187c 100755 --- a/scripts/guest/check_mounted_directories +++ b/scripts/guest/check_mounted_directories @@ -1,8 +1,8 @@ #!/usr/bin/env bash -vagrant_dir="/vagrant" +vagrant_dir="${VAGRANT_ROOT}" -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" status "Checking if all required directories were mounted successfully" incrementNestingLevel @@ -14,8 +14,8 @@ if [[ ! -f "${MAGENTO_ROOT}/bin/magento" ]]; then exit 1 fi -if [[ ! -f "/vagrant/etc/config.yaml" ]]; then - error "Directory '/vagrant/etc' was not mounted as expected by Vagrant and is not accessible on the guest machine. +if [[ ! -f "${vagrant_dir}/etc/config.yaml" ]]; then + error "Directory '${vagrant_dir}/etc' was not mounted as expected by Vagrant and is not accessible on the guest machine. Please make sure that Vagrant is able to mount VirtualBox shared folders on your environment (see https://www.vagrantup.com/docs/synced-folders/basic_usage.html ). Also remove any stale declarations from /etc/exports on the host." exit 1 diff --git a/scripts/guest/composer.sh b/scripts/guest/composer.sh new file mode 100755 index 00000000..b66ef0ad --- /dev/null +++ b/scripts/guest/composer.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +# This script allows to use credentials specified in etc/composer/auth.json without declaring them globally + +cd "$(dirname "${BASH_SOURCE[0]}")/../.." && vagrant_dir=$PWD + +source "${vagrant_dir}/scripts/functions.sh" + +status "Executing composer command" +incrementNestingLevel + +composer_auth_json="${vagrant_dir}/etc/composer/auth.json" + +# commented out due to composer conflicts +# ${php_executable} "${composer_phar}" global require "hirak/prestissimo:^0.3" + +cd "${VAGRANT_ROOT}/magento" +if [[ -f ${composer_auth_json} ]]; then + status "Exporting etc/auth.json to environment variable" + export COMPOSER_AUTH="$(cat "${composer_auth_json}")" +fi + +status "composer --no-interaction "$@"" +composer --no-interaction "$@" 2> >(log) > >(log) + +decrementNestingLevel diff --git a/scripts/guest/configure_cache_backend b/scripts/guest/configure_cache_backend deleted file mode 100755 index eff8e1c5..00000000 --- a/scripts/guest/configure_cache_backend +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env bash - -vagrant_dir="/vagrant" - -source "${vagrant_dir}/scripts/output_functions.sh" - -status "Configuring cache backend according to config.yaml" -incrementNestingLevel - -cache_backend="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "environment_cache_backend")" -magento_composer_content="$(cat "${MAGENTO_ROOT}/composer.json")" -redis_configuration=", - 'cache' => [ - 'frontend' => [ - 'default' => [ - 'backend' => 'Cm_Cache_Backend_Redis', - 'backend_options' => [ - 'server' => '127.0.0.1', - 'port' => '6379' - ], - ], - 'page_cache' => [ - 'backend' => 'Cm_Cache_Backend_Redis', - 'backend_options' => [ - 'server' => '127.0.0.1', - 'port' => '6379', - 'database' => '1', - 'compress_data' => '0' - ] - ] - ] - ], -" - -# Removing existing configuration -perl -i -p0e "s/,\s*'cache'.*,/,/smg" "${MAGENTO_ROOT}/app/etc/env.php" - -incompatible_magento_version_pattern='"version": "2.0.[0-5]' -if [[ ${cache_backend} == "redis" ]] && [[ ! ${magento_composer_content} =~ ${incompatible_magento_version_pattern} ]]; then - status "Using Redis backend for caching" - perl -i -p0e "s/,?\n*\);/${redis_configuration});/smg" "${MAGENTO_ROOT}/app/etc/env.php" - perl -i -p0e "s/,?\n*\];/${redis_configuration}];/smg" "${MAGENTO_ROOT}/app/etc/env.php" - redis-cli flushall 2> >(logError) > >(log) -else - status "Using file system backend for caching" -fi - -decrementNestingLevel diff --git a/scripts/guest/configure_debugging b/scripts/guest/configure_debugging index 8dfa97af..64e5cef4 100755 --- a/scripts/guest/configure_debugging +++ b/scripts/guest/configure_debugging @@ -1,29 +1,29 @@ #!/usr/bin/env bash -vagrant_dir="/vagrant" +vagrant_dir="${VAGRANT_ROOT}" -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" debug_magento_storefront="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_magento_storefront")" if [[ ${debug_magento_storefront} == 1 ]]; then status "Enabling Magento storefront debugging (as specified in etc/config.yaml)" incrementNestingLevel - update_magento_config 'dev/debug/template_hints_storefront' '1' - update_magento_config 'dev/debug/template_hints_blocks' '1' + "${VAGRANT_ROOT}/scripts/guest/update_magento_config" 'dev/debug/template_hints_storefront' '1' + "${VAGRANT_ROOT}/scripts/guest/update_magento_config" 'dev/debug/template_hints_blocks' '1' decrementNestingLevel else - update_magento_config 'dev/debug/template_hints_storefront' '0' 2> >(logError) > >(log) - update_magento_config 'dev/debug/template_hints_blocks' '0' 2> >(logError) > >(log) + "${VAGRANT_ROOT}/scripts/guest/update_magento_config" 'dev/debug/template_hints_storefront' '0' 2> >(logError) > >(log) + "${VAGRANT_ROOT}/scripts/guest/update_magento_config" 'dev/debug/template_hints_blocks' '0' 2> >(logError) > >(log) fi debug_magento_admin="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_magento_admin")" if [[ ${debug_magento_admin} == 1 ]]; then status "Enabling Magento admin debugging (as specified in etc/config.yaml)" incrementNestingLevel - update_magento_config 'dev/debug/template_hints_admin' '1' + "${VAGRANT_ROOT}/scripts/guest/update_magento_config" 'dev/debug/template_hints_admin' '1' decrementNestingLevel else - update_magento_config 'dev/debug/template_hints_admin' '0' 2> >(logError) > >(log) + "${VAGRANT_ROOT}/scripts/guest/update_magento_config" 'dev/debug/template_hints_admin' '0' 2> >(logError) > >(log) fi # Switch to desired Magento mode diff --git a/scripts/guest/configure_search_engine b/scripts/guest/configure_search_engine index dcac3986..cb7684ab 100755 --- a/scripts/guest/configure_search_engine +++ b/scripts/guest/configure_search_engine @@ -1,33 +1,33 @@ #!/usr/bin/env bash # Init environment variables -vagrant_dir="/vagrant" +vagrant_dir="${VAGRANT_ROOT}" -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" status "Configuring search engine according to config.yaml" incrementNestingLevel -if [[ -z "$(grep "search_engine:" /vagrant/etc/config.yaml)" ]]; then - sed -i '/environment:/a \ \ search_engine: "mysql"' /vagrant/etc/config.yaml +if [[ -z "$(grep "search_engine:" ${vagrant_dir}/etc/config.yaml)" ]]; then + sed -i '/environment:/a \ \ search_engine: "mysql"' ${vagrant_dir}/etc/config.yaml fi if [[ -f "${MAGENTO_ROOT}/LICENSE_EE.txt" ]]; then search_engine="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "environment_search_engine")" if [[ ${search_engine} == "elasticsearch" ]]; then status "Configuring ElasticSearch search engine" - update_magento_config 'catalog/search/engine' 'elasticsearch' - update_magento_config 'catalog/search/elasticsearch_server_hostname' 'localhost' - update_magento_config 'catalog/search/elasticsearch_server_port' '9200' - update_magento_config 'catalog/search/elasticsearch_index_prefix' 'magento2' - update_magento_config 'catalog/search/elasticsearch_enable_auth' '0' - update_magento_config 'catalog/search/elasticsearch_server_timeout' '15' + "${VAGRANT_ROOT}/scripts/guest/update_magento_config" 'catalog/search/engine' 'elasticsearch' + "${VAGRANT_ROOT}/scripts/guest/update_magento_config" 'catalog/search/elasticsearch_server_hostname' 'localhost' + "${VAGRANT_ROOT}/scripts/guest/update_magento_config" 'catalog/search/elasticsearch_server_port' '9200' + "${VAGRANT_ROOT}/scripts/guest/update_magento_config" 'catalog/search/elasticsearch_index_prefix' 'magento2' + "${VAGRANT_ROOT}/scripts/guest/update_magento_config" 'catalog/search/elasticsearch_enable_auth' '0' + "${VAGRANT_ROOT}/scripts/guest/update_magento_config" 'catalog/search/elasticsearch_server_timeout' '15' elif [[ ${search_engine} == "mysql" ]]; then status "Configuring MySQL search engine" - update_magento_config 'catalog/search/engine' 'mysql' + "${VAGRANT_ROOT}/scripts/guest/update_magento_config" 'catalog/search/engine' 'mysql' fi - bash m-clear-cache + bash "${VAGRANT_ROOT}/scripts/guest/m-clear-cache" status "Rebuilding catalog search index" php "${MAGENTO_ROOT}/bin/magento" indexer:reindex catalogsearch_fulltext 2> >(logError) > >(log) diff --git a/scripts/guest/configure_varnish b/scripts/guest/configure_varnish index 1ae2f60a..6da7e8c4 100755 --- a/scripts/guest/configure_varnish +++ b/scripts/guest/configure_varnish @@ -1,8 +1,8 @@ #!/usr/bin/env bash -vagrant_dir="/vagrant" +vagrant_dir="${VAGRANT_ROOT}" -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" status "Configuring Varnish FPC according to config.yaml" incrementNestingLevel @@ -15,8 +15,8 @@ while getopts 'f' flag; do esac done -if [[ -z "$(grep "use_varnish:" /vagrant/etc/config.yaml)" ]]; then - sed -i '/environment:/a \ \ use_varnish: 0' /vagrant/etc/config.yaml +if [[ -z "$(grep "use_varnish:" "${vagrant_dir}/etc/config.yaml")" ]]; then + sed -i '/environment:/a \ \ use_varnish: 0' "${vagrant_dir}/etc/config.yaml" fi # Configure Varnish if enabled in config @@ -38,7 +38,8 @@ if [[ $use_varnish == 1 ]]; then fi status "Updating Magento database to use varnish FPC" - mysql -D magento -e "INSERT INTO core_config_data + # TODO: Make credentials configurable + mysql -u"root" -p"1234" -h"magento2-mysql" -D magento -e "INSERT INTO core_config_data ( scope, scope_id, path, value ) VALUES ( 'default', '0', 'system/full_page_cache/caching_application', '2' ) ON DUPLICATE KEY UPDATE value = 2 @@ -59,7 +60,7 @@ else fi status "Updating Magento database to not use varnish FPC" - mysql -D magento -e "INSERT INTO core_config_data + mysql -u"root" -p"1234" -h"magento2-mysql" -D magento -e "INSERT INTO core_config_data ( scope, scope_id, path, value ) VALUES ( 'default', '0', 'system/full_page_cache/caching_application', '1' ) ON DUPLICATE KEY UPDATE value = 1 @@ -79,7 +80,7 @@ if [[ $restart_services == 1 ]]; then if [[ $use_varnish == 1 ]]; then sudo varnishd -f /etc/varnish/default.vcl fi - bash m-clear-cache + bash "${VAGRANT_ROOT}/scripts/guest/m-clear-cache" fi decrementNestingLevel diff --git a/scripts/guest/generate_basic_data b/scripts/guest/generate_basic_data index 5a75c78a..e97a4c4a 100755 --- a/scripts/guest/generate_basic_data +++ b/scripts/guest/generate_basic_data @@ -1,12 +1,12 @@ #!/usr/bin/env bash -vagrant_dir="/vagrant" +vagrant_dir="${VAGRANT_ROOT}" -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" host_name="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "magento_host_name")" -status "Generating sample data" +status "Generating basic data" incrementNestingLevel diff --git a/scripts/guest/link_configs b/scripts/guest/link_configs index 9bac600e..5cfb1f2b 100755 --- a/scripts/guest/link_configs +++ b/scripts/guest/link_configs @@ -1,41 +1,41 @@ #!/usr/bin/env bash -function process_configs () { - configs_path=$1 - configs=$2 - for config in "${configs[@]}" - do - if [[ ! -d /vagrant/etc/guest/${config} ]] && [[ ! -f /vagrant/etc/guest/${config} ]]; then - if [[ -d ${configs_path}/${config} ]] || [[ -f ${configs_path}/${config} ]]; then - sudo rm -rf "${configs_path}/${config}.back" - sudo cp -rp ${configs_path}/${config} "${configs_path}/${config}.back" - sudo mv ${configs_path}/${config} /vagrant/etc/guest/${config} - sudo ln -s /vagrant/etc/guest/${config} ${configs_path}/${config} - fi - fi - done -} - -vagrant_dir="/vagrant" - -source "${vagrant_dir}/scripts/output_functions.sh" - -# Below configuration is required to allow managing mysql as a service -if ! cat /etc/apparmor.d/local/usr.sbin.mysqld | grep -q '/vagrant/etc/guest' ; then - echo " - /vagrant/etc/guest/mysql/*.pem r, - /vagrant/etc/guest/mysql/conf.d/ r, - /vagrant/etc/guest/mysql/conf.d/* r, - /vagrant/etc/guest/mysql/*.cnf r," >> /etc/apparmor.d/local/usr.sbin.mysqld -fi - -status "Making guest configs visible and editable in the host IDE" -incrementNestingLevel - -# Configs located under /etc/* -config_dir="/etc" -# See unlink_configs script -configs=( apache2 php mysql varnish rabbitmq ) -process_configs ${config_dir} ${configs} +#function process_configs () { +# configs_path=$1 +# configs=$2 +# for config in "${configs[@]}" +# do +# if [[ ! -d ${vagrant_dir}/etc/guest/${config} ]] && [[ ! -f ${vagrant_dir}/etc/guest/${config} ]]; then +# if [[ -d ${configs_path}/${config} ]] || [[ -f ${configs_path}/${config} ]]; then +# sudo rm -rf "${configs_path}/${config}.back" +# sudo cp -rp ${configs_path}/${config} "${configs_path}/${config}.back" +# sudo mv ${configs_path}/${config} ${vagrant_dir}/etc/guest/${config} +# sudo ln -s ${vagrant_dir}/etc/guest/${config} ${configs_path}/${config} +# fi +# fi +# done +#} +# +#vagrant_dir="${vagrant_dir}" +# +#source "${vagrant_dir}/scripts/functions.sh" +# +## Below configuration is required to allow managing mysql as a service +#if ! cat /etc/apparmor.d/local/usr.sbin.mysqld | grep -q '${vagrant_dir}/etc/guest' ; then +# echo " +# ${vagrant_dir}/etc/guest/mysql/*.pem r, +# ${vagrant_dir}/etc/guest/mysql/conf.d/ r, +# ${vagrant_dir}/etc/guest/mysql/conf.d/* r, +# ${vagrant_dir}/etc/guest/mysql/*.cnf r," >> /etc/apparmor.d/local/usr.sbin.mysqld +#fi +# +#status "Making guest configs visible and editable in the host IDE" +#incrementNestingLevel +# +## Configs located under /etc/* +#config_dir="/etc" +## See unlink_configs script +#configs=( apache2 php mysql varnish rabbitmq ) +#process_configs ${config_dir} ${configs} decrementNestingLevel diff --git a/scripts/guest/m-clear-cache b/scripts/guest/m-clear-cache index 9d481445..ffe8aa0a 100755 --- a/scripts/guest/m-clear-cache +++ b/scripts/guest/m-clear-cache @@ -1,8 +1,8 @@ #!/usr/bin/env bash -vagrant_dir="/vagrant" +vagrant_dir="${VAGRANT_ROOT}" -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" if [[ ${SKIP_CACHE_CLEAN} -eq 1 ]] ; then exit 0 @@ -60,11 +60,12 @@ if [[ -d "${MAGENTO_ROOT}/dev" ]]; then fi fi -if [[ -f "${MAGENTO_ROOT}/app/etc/env.php" ]]; then +status "Flushing redis storage" +redis-cli -h magento2-redis-master flushall 2> >(logError) > >(log) - bash configure_debugging +if [[ -f "${MAGENTO_ROOT}/app/etc/env.php" ]]; then - bash configure_cache_backend + bash "${VAGRANT_ROOT}/scripts/guest/configure_debugging" status "Flushing cache using 'bin/magento cache:flush'" php "${MAGENTO_ROOT}/bin/magento" cache:flush 2> >(logError) > >(log) diff --git a/scripts/guest/m-reinstall b/scripts/guest/m-reinstall index a99184cf..6bcea661 100755 --- a/scripts/guest/m-reinstall +++ b/scripts/guest/m-reinstall @@ -1,10 +1,10 @@ #!/usr/bin/env bash -vagrant_dir="/vagrant" +vagrant_dir="${VAGRANT_ROOT}" -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" -get_config_value="/vagrant/scripts/get_config_value.sh" +get_config_value="${vagrant_dir}/scripts/get_config_value.sh" magento_host_name="$(bash ${get_config_value} "magento_host_name")" use_nfs="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "guest_use_nfs")" is_windows_host=${IS_WINDOWS_HOST} @@ -17,9 +17,10 @@ setupOptions[timezone]="$(bash ${get_config_value} "magento_timezone")" setupOptions[currency]="$(bash ${get_config_value} "magento_currency")" setupOptions[admin_user]="$(bash ${get_config_value} "magento_admin_user")" setupOptions[admin_password]="$(bash ${get_config_value} "magento_admin_password")" -setupOptions[db_host]='localhost' +setupOptions[db_host]='magento2-mysql' setupOptions[db_name]='magento' setupOptions[db_user]='root' +setupOptions[db_password]='1234' setupOptions[base_url]="http://${magento_host_name}/" setupOptions[admin_lastname]='Admin' setupOptions[admin_firstname]='Admin' @@ -30,12 +31,12 @@ setupOptions[amqp_user]='guest' setupOptions[amqp_password]='guest' setupOptions[amqp_virtualhost]='/' -if [[ ${is_windows_host} == 1 ]] || [[ ${use_nfs} == 0 ]]; then - sudo chown -R vagrant:vagrant ${MAGENTO_ROOT} -fi - -status "Killing MQ processes" -pkill -f queue +#if [[ ${is_windows_host} == 1 ]] || [[ ${use_nfs} == 0 ]]; then +# sudo chown -R vagrant:vagrant ${MAGENTO_ROOT} +#fi +# +#status "Killing MQ processes" +#pkill -f queue status "Installing/re-installing Magento" incrementNestingLevel @@ -49,14 +50,14 @@ rm -f "${MAGENTO_ROOT}/app/etc/env.php" status "Restoring stored in git config.php (if applicable)" git checkout "${MAGENTO_ROOT}/app/etc/config.php" &>/dev/null -bash m-clear-cache +bash "${VAGRANT_ROOT}/scripts/guest/m-clear-cache" # Cache cleaning takes 5-10 seconds and should be avoided until the end of installation to speed up the process export SKIP_CACHE_CLEAN=1 db_names=("${setupOptions[db_name]}" "magento_integration_tests" ) for db_name in "${db_names[@]}"; do status "Dropping and creating '${db_name}' DB" - mysql -e "drop database if exists ${db_name}; create database ${db_name};" + mysql -u"${setupOptions[db_user]}" -p"${setupOptions[db_password]}" -h"${setupOptions[db_host]}" -e"drop database if exists ${db_name}; create database ${db_name};" done # Install Magento application @@ -66,6 +67,7 @@ install_cmd="./bin/magento setup:install \ --db-host=${setupOptions[db_host]} \ --db-name=${setupOptions[db_name]} \ --db-user=${setupOptions[db_user]} \ + --db-password=${setupOptions[db_password]} \ --backend-frontname=${setupOptions[admin_frontname]} \ --base-url=${setupOptions[base_url]} \ --language=${setupOptions[language]} \ @@ -80,62 +82,71 @@ install_cmd="./bin/magento setup:install \ --use-rewrites=1" # Configure Rabbit MQ -if [[ -d "${MAGENTO_ROOT}/app/code/Magento/MessageQueue" ]] || [[ -d "${MAGENTO_ROOT}/vendor/magento/module-message-queue" ]]; then - install_cmd="${install_cmd} \ - --amqp-host=${setupOptions[amqp_host]} \ - --amqp-port=${setupOptions[amqp_port]} \ - --amqp-user=${setupOptions[amqp_user]} \ - --amqp-virtualhost=${setupOptions[amqp_virtualhost]} \ - --amqp-password=${setupOptions[amqp_password]}" -fi - -sudo chmod +x bin/magento +# TODO: Enable Rabbit MQ +#if [[ -d "${MAGENTO_ROOT}/app/code/Magento/MessageQueue" ]] || [[ -d "${MAGENTO_ROOT}/vendor/magento/module-message-queue" ]]; then +# install_cmd="${install_cmd} \ +# --amqp-host=${setupOptions[amqp_host]} \ +# --amqp-port=${setupOptions[amqp_port]} \ +# --amqp-user=${setupOptions[amqp_user]} \ +# --amqp-virtualhost=${setupOptions[amqp_virtualhost]} \ +# --amqp-password=${setupOptions[amqp_password]}" +#fi + +# TODO: Permission denied +#sudo chmod +x bin/magento status "${install_cmd}" php ${install_cmd} 2> >(logError) > >(log) # Comment out the line above and uncomment the one below to debug Magento Setup script # php -d xdebug.remote_autostart=1 ${install_cmd} 2> >(logError) > >(log) +#status "Configuring Redis as cache backend" +php "${MAGENTO_ROOT}/bin/magento" setup:config:set --page-cache=redis --page-cache-redis-server=magento2-redis-master +php "${MAGENTO_ROOT}/bin/magento" setup:config:set --cache-backend=redis --cache-backend-redis-server=magento2-redis-master + if [[ $? != 0 ]]; then error "Magento installation failed." exit 1 fi -bash "${vagrant_dir}/scripts/guest/configure_varnish" -f +# TODO: Confibure varnish +#bash "${vagrant_dir}/scripts/guest/configure_varnish" -f -status "Enabling Magento cron jobs" -echo "* * * * * php ${MAGENTO_ROOT}/bin/magento cron:run & -* * * * * php ${MAGENTO_ROOT}/update/cron.php & -* * * * * php ${MAGENTO_ROOT}/bin/magento setup:cron:run &" | crontab -u vagrant - +# TODO: Enable cron +#status "Enabling Magento cron jobs" +#echo "* * * * * php ${MAGENTO_ROOT}/bin/magento cron:run & +#* * * * * php ${MAGENTO_ROOT}/update/cron.php & +#* * * * * php ${MAGENTO_ROOT}/bin/magento setup:cron:run &" | crontab -u vagrant - -if [[ ${is_windows_host} == 1 ]] || [[ ${use_nfs} == 0 ]]; then - status "Changing ownership of "${MAGENTO_ROOT}" to vagrant:vagrant" - sudo chown -R vagrant:vagrant ${MAGENTO_ROOT} -fi +# TODO: Remove +#if [[ ${is_windows_host} == 1 ]] || [[ ${use_nfs} == 0 ]]; then +# status "Changing ownership of "${MAGENTO_ROOT}" to vagrant:vagrant" +# sudo chown -R vagrant:vagrant ${MAGENTO_ROOT} +#fi if [[ ${generate_basic_data} != 0 ]]; then - bash generate_basic_data + bash "${VAGRANT_ROOT}/scripts/guest/generate_basic_data" fi -bash configure_search_engine -bash change_magento_config_for_functional_tests -bash update_magento_config 'admin/security/session_lifetime' '86400' +bash "${VAGRANT_ROOT}/scripts/guest/configure_search_engine" +bash "${VAGRANT_ROOT}/scripts/guest/change_magento_config_for_functional_tests" +bash "${VAGRANT_ROOT}/scripts/guest/update_magento_config" 'admin/security/session_lifetime' '86400' export SKIP_CACHE_CLEAN=0 -bash m-clear-cache +bash "${VAGRANT_ROOT}/scripts/guest/m-clear-cache" status "Checking if Magento frontend is accessible at '${setupOptions[base_url]}'" magento_home_page_content="$(curl -sL ${setupOptions[base_url]})" pattern="All rights reserved." if [[ ${magento_home_page_content} =~ ${pattern} ]]; then - bash warm_up_cache + bash "${VAGRANT_ROOT}/scripts/guest/warm_up_cache" status "Generating XSD references for PHP Storm" - php bin/magento dev:urn-catalog:generate /vagrant/.idea/misc.xml - sed -i "s|${MAGENTO_ROOT}|${MAGENTO_ROOT_HOST}|g" "/vagrant/.idea/misc.xml" + php "${MAGENTO_ROOT}/bin/magento" dev:urn-catalog:generate "${vagrant_dir}/.idea/misc.xml" + sed -i "s|${MAGENTO_ROOT}|${MAGENTO_ROOT_HOST}|g" "${vagrant_dir}/.idea/misc.xml" decrementNestingLevel success "Magento reinstalled successfully" - info "Magento application was deployed to $(bold)${MAGENTO_ROOT}$(regular) and installed successfully + info "$(regular)Magento application was deployed to $(bold)${MAGENTO_ROOT}$(regular) and installed successfully Access storefront at $(bold)${setupOptions[base_url]}$(regular) Access admin panel at $(bold)${setupOptions[base_url]}${setupOptions[admin_frontname]}/$(regular)" diff --git a/scripts/guest/m-search-engine b/scripts/guest/m-search-engine index c0fd5c7b..ff195348 100755 --- a/scripts/guest/m-search-engine +++ b/scripts/guest/m-search-engine @@ -1,8 +1,8 @@ #!/usr/bin/env bash -vagrant_dir="/vagrant" +vagrant_dir="${VAGRANT_ROOT}" -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" status "Configuring search engine" incrementNestingLevel @@ -15,28 +15,28 @@ fi # Check if user created config.yaml file -if [[ ! -f /vagrant/etc/config.yaml ]]; then +if [[ ! -f ${vagrant_dir}/etc/config.yaml ]]; then error "Please make sure you have create a config.yaml file copy from etc/config.yaml.dist" decrementNestingLevel exit 1 fi -if [[ -z "$(grep "search_engine:" /vagrant/etc/config.yaml)" ]]; then - sed -i '/environment:/a \ \ search_engine: "mysql"' /vagrant/etc/config.yaml +if [[ -z "$(grep "search_engine:" ${vagrant_dir}/etc/config.yaml)" ]]; then + sed -i '/environment:/a \ \ search_engine: "mysql"' ${vagrant_dir}/etc/config.yaml fi if [[ $1 == "mysql" ]]; then status "Enabling MySQL search engine" - sed -ie 's/search_engine:.*/search_engine: "mysql"/' /vagrant/etc/config.yaml + sed -ie 's/search_engine:.*/search_engine: "mysql"/' ${vagrant_dir}/etc/config.yaml elif [[ $1 == "elasticsearch" ]]; then status "Enabling ElasticSearch search engine" - sed -ie 's/search_engine:.*/search_engine: "elasticsearch"/' /vagrant/etc/config.yaml + sed -ie 's/search_engine:.*/search_engine: "elasticsearch"/' ${vagrant_dir}/etc/config.yaml else error "Usage: ./m-search-engine mysql|elasticsearch" decrementNestingLevel exit 1 fi -bash configure_search_engine +bash "${VAGRANT_ROOT}/scripts/guest/configure_search_engine" decrementNestingLevel diff --git a/scripts/guest/m-varnish b/scripts/guest/m-varnish index 5880adbb..225b3613 100755 --- a/scripts/guest/m-varnish +++ b/scripts/guest/m-varnish @@ -1,8 +1,8 @@ #!/usr/bin/env bash -vagrant_dir="/vagrant" +vagrant_dir="${VAGRANT_ROOT}" -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" status "Configuring Varnish" incrementNestingLevel @@ -14,22 +14,22 @@ if [[ $1 == "help" ]]; then fi # Check if user created config.yaml file -if [[ ! -f /vagrant/etc/config.yaml ]]; then +if [[ ! -f ${vagrant_dir}/etc/config.yaml ]]; then error "Please make sure you have create a config.yaml file copy from etc/config.yaml.dist" decrementNestingLevel exit 1 fi -if [[ -z "$(grep "use_varnish:" /vagrant/etc/config.yaml)" ]]; then - sed -i '/environment:/a \ \ use_varnish: 0' /vagrant/etc/config.yaml +if [[ -z "$(grep "use_varnish:" ${vagrant_dir}/etc/config.yaml)" ]]; then + sed -i '/environment:/a \ \ use_varnish: 0' ${vagrant_dir}/etc/config.yaml fi if [[ $1 == "enable" ]]; then status "Enabling Varnish" - sed -ie "s/use_varnish:.*/use_varnish: 1/" /vagrant/etc/config.yaml + sed -ie "s/use_varnish:.*/use_varnish: 1/" ${vagrant_dir}/etc/config.yaml elif [[ $1 == "disable" ]]; then status "Disabling Varnish" - sed -ie "s/use_varnish:.*/use_varnish: 0/" /vagrant/etc/config.yaml + sed -ie "s/use_varnish:.*/use_varnish: 0/" ${vagrant_dir}/etc/config.yaml else error "Usage: ./m-varnish enable|disable" decrementNestingLevel diff --git a/scripts/guest/unlink_configs b/scripts/guest/unlink_configs index f78b3a91..e5885b40 100755 --- a/scripts/guest/unlink_configs +++ b/scripts/guest/unlink_configs @@ -1,31 +1,31 @@ #!/usr/bin/env bash -function process_configs () { - configs_path=$1 - configs=$2 - for config in "${configs[@]}" - do - if [[ -L ${config_dir}/${config} ]] && [[ -e ${config_dir}/${config} ]]; then - sudo rm ${config_dir}/${config} - sudo mv /vagrant/etc/guest/${config} ${config_dir}/${config} - elif [[ ! -e ${config_dir}/${config} ]] && [[ -e "${config_dir}/${config}.back" ]]; then - sudo rm -rf ${config_dir}/${config} - sudo cp -rp "${config_dir}/${config}.back" ${config_dir}/${config} - fi - done -} - -vagrant_dir="/vagrant" - -source "${vagrant_dir}/scripts/output_functions.sh" - -status "Reverting configs before shutdown or reboot to allow proper services initialization on booting" -incrementNestingLevel - -# Configs located under /etc/* -config_dir="/etc" -# See link_configs script -configs=( apache2 php mysql varnish rabbitmq ) -process_configs ${config_dir} ${configs} +#function process_configs () { +# configs_path=$1 +# configs=$2 +# for config in "${configs[@]}" +# do +# if [[ -L ${config_dir}/${config} ]] && [[ -e ${config_dir}/${config} ]]; then +# sudo rm ${config_dir}/${config} +# sudo mv ${vagrant_dir}/etc/guest/${config} ${config_dir}/${config} +# elif [[ ! -e ${config_dir}/${config} ]] && [[ -e "${config_dir}/${config}.back" ]]; then +# sudo rm -rf ${config_dir}/${config} +# sudo cp -rp "${config_dir}/${config}.back" ${config_dir}/${config} +# fi +# done +#} +# +#vagrant_dir="${vagrant_dir}" +# +#source "${vagrant_dir}/scripts/functions.sh" +# +#status "Reverting configs before shutdown or reboot to allow proper services initialization on booting" +#incrementNestingLevel +# +## Configs located under /etc/* +#config_dir="/etc" +## See link_configs script +#configs=( apache2 php mysql varnish rabbitmq ) +#process_configs ${config_dir} ${configs} decrementNestingLevel diff --git a/scripts/guest/update_magento_config b/scripts/guest/update_magento_config index 103001b0..6af48579 100755 --- a/scripts/guest/update_magento_config +++ b/scripts/guest/update_magento_config @@ -1,8 +1,8 @@ #!/usr/bin/env bash -vagrant_dir="/vagrant" +vagrant_dir="${VAGRANT_ROOT}" -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" config_path=$1 config_value=$2 @@ -10,7 +10,7 @@ config_value=$2 status "Updating Magento config: ${config_path} = ${config_value}" incrementNestingLevel -mysql -D magento -e "INSERT INTO core_config_data +mysql -u"root" -p"1234" -h"magento2-mysql" -D magento -e "INSERT INTO core_config_data ( scope, scope_id, path, value ) VALUES ( 'default', '0', '${config_path}', '${config_value}' ) ON DUPLICATE KEY UPDATE value = '${config_value}' diff --git a/scripts/guest/warm_up_cache b/scripts/guest/warm_up_cache index aa8923a4..0515d31c 100755 --- a/scripts/guest/warm_up_cache +++ b/scripts/guest/warm_up_cache @@ -2,7 +2,7 @@ cd "$(dirname "${BASH_SOURCE[0]}")/../.." && vagrant_dir=$PWD -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" function loadByUrl() { diff --git a/scripts/host/.gitignore b/scripts/host/.gitignore index 257f52bf..69f392be 100755 --- a/scripts/host/.gitignore +++ b/scripts/host/.gitignore @@ -1,2 +1,2 @@ /composer.phar -/magento2ce.tar \ No newline at end of file +/magento.tar diff --git a/scripts/host/check_mounted_directories.sh b/scripts/host/check_mounted_directories.sh index e6540b31..9a7361a8 100755 --- a/scripts/host/check_mounted_directories.sh +++ b/scripts/host/check_mounted_directories.sh @@ -2,16 +2,16 @@ cd "$(dirname "${BASH_SOURCE[0]}")/../.." && vagrant_dir=$PWD -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" cd "${vagrant_dir}" -if [[ ! -f "${vagrant_dir}/etc/guest/mysql/my.cnf" ]]; then - error "Directory '${vagrant_dir}/etc' was not mounted as expected by Vagrant. - Please make sure that 'paliarush/magento2.ubuntu' Vagrant box was downloaded successfully (if not, this may help http://stackoverflow.com/questions/35519389/vagrant-cannot-find-box) - And that Vagrant is able to mount VirtualBox shared folders on your environment (see https://www.vagrantup.com/docs/synced-folders/basic_usage.html ). - Also remove any stale declarations from /etc/exports on the host." - exit 1 -fi -vagrant ssh -c "bash /vagrant/scripts/guest/check_mounted_directories" 2> >(logError) +#if [[ ! -f "${vagrant_dir}/magento/composer.json" ]]; then +# error "Directory '${vagrant_dir}/magento' was not mounted as expected by Vagrant. +# Please make sure that 'paliarush/magento2.ubuntu' Vagrant box was downloaded successfully (if not, this may help http://stackoverflow.com/questions/35519389${vagrant_dir}-cannot-find-box) +# And that Vagrant is able to mount VirtualBox shared folders on your environment (see https://www.vagrantup.com/docs/synced-folders/basic_usage.html ). +# Also remove any stale declarations from /etc/exports on the host." +# exit 1 +#fi +executeInMagento2Container bash -- "${vagrant_dir}/scripts/guest/check_mounted_directories" 2> >(logError) # Explicit exit is necessary to bypass incorrect output from vagrant in case of errors exit 0 diff --git a/scripts/host/check_requirements.sh b/scripts/host/check_requirements.sh index 76ee3bc4..efee0f60 100755 --- a/scripts/host/check_requirements.sh +++ b/scripts/host/check_requirements.sh @@ -2,15 +2,15 @@ cd "$(dirname "${BASH_SOURCE[0]}")/../.." && vagrant_dir=$PWD -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" status "Checking requirements" incrementNestingLevel -php_executable="$(bash "${vagrant_dir}/scripts/host/get_path_to_php.sh")" - -if ! ${php_executable} -v 2> >(log) | grep -q 'Copyright' ; then - bash "${vagrant_dir}/scripts/host/install_php.sh" +nfs_exports_record="\"${vagrant_dir}\" -alldirs -mapall=$(id -u):$(id -g) -mask 255.0.0.0 -network 192.0.0.0" +if [[ -z "$(grep "${nfs_exports_record}" /etc/exports)" ]]; then + warning "NFS exports configuration required on the host. Please execute 'sudo ${vagrant_dir}/scripts/host/configure_nfs_exports.sh' first." + exit 1 fi decrementNestingLevel diff --git a/scripts/host/composer.sh b/scripts/host/composer.sh deleted file mode 100755 index 94312742..00000000 --- a/scripts/host/composer.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env bash - -# This script allows to use credentials specified in etc/composer/auth.json without declaring them globally - -current_dir=${PWD} -cd "$(dirname "${BASH_SOURCE[0]}")/../.." && vagrant_dir=$PWD - -source "${vagrant_dir}/scripts/output_functions.sh" - -status "Executing composer command" -incrementNestingLevel - -composer_auth_json="${vagrant_dir}/etc/composer/auth.json" -composer_dir="${vagrant_dir}/scripts/host" -composer_phar="${composer_dir}/composer.phar" - -bash "${vagrant_dir}/scripts/host/check_requirements.sh" - -php_executable="$(bash "${vagrant_dir}/scripts/host/get_path_to_php.sh")" - -if [[ ! -f ${composer_phar} ]]; then - status "Installing composer" - cd "${composer_dir}" - curl -sS https://getcomposer.org/installer | ${php_executable} 2> >(logError) > >(log) -fi - -# commented out due to composer conflicts -# ${php_executable} "${composer_phar}" global require "hirak/prestissimo:^0.3" - -cd "${current_dir}" -if [[ -f ${composer_auth_json} ]]; then - status "Exporting etc/auth.json to environment variable" - export COMPOSER_AUTH="$(cat "${composer_auth_json}")" -fi - -host_os="$(bash "${vagrant_dir}/scripts/host/get_host_os.sh")" -if [[ $(bash "${vagrant_dir}/scripts/get_config_value.sh" "environment_composer_prefer_source") == 1 ]]; then - # prefer-source is slow but guarantees that there will be no issues related to max path length on Windows - status "composer --ignore-platform-reqs --prefer-source --no-interaction "$@"" - "${php_executable}" "${composer_phar}" --ignore-platform-reqs --prefer-source --no-interaction "$@" 2> >(log) > >(log) -else - status "composer --ignore-platform-reqs --no-interaction "$@"" - "${php_executable}" "${composer_phar}" --ignore-platform-reqs --no-interaction "$@" 2> >(log) > >(log) -fi - -decrementNestingLevel diff --git a/scripts/host/configure_nfs_exports.sh b/scripts/host/configure_nfs_exports.sh new file mode 100755 index 00000000..380d906f --- /dev/null +++ b/scripts/host/configure_nfs_exports.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "${BASH_SOURCE[0]}")/../.." && vagrant_dir=$PWD + +source "${vagrant_dir}/scripts/functions.sh" +resetNestingLevel +current_script_name=`basename "$0"` +initLogFile ${current_script_name} + +debug_vagrant_project="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "debug_vagrant_project")" +if [[ ${debug_vagrant_project} -eq 1 ]]; then + set -x +fi + +nfs_exports_record="\"${vagrant_dir}\" -alldirs -mapall=$(id -u):$(id -g) -mask 255.0.0.0 -network 192.0.0.0" +if [[ -z "$(grep "${nfs_exports_record}" /etc/exports)" ]]; then + status "Updating /etc/exports to enable codebase sharing with containers via NFS" + echo "${nfs_exports_record}" | sudo tee -a "/etc/exports" 2> >(logError) > >(log) + sudo nfsd restart + # TODO: Implement NFS exports clean up on project removal to prevent NFS mounting errors +else + status "NFS exports are properly configured and do not need to be updated" +fi + +info "$(regular)See details in $(bold)${vagrant_dir}/log/${current_script_name}.log$(regular). For debug output set $(bold)debug:vagrant_project$(regular) to $(bold)1$(regular) in $(bold)etc/config.yaml$(regular)" diff --git a/scripts/host/configure_php_storm.sh b/scripts/host/configure_php_storm.sh index 36a46ee8..f855fa8a 100755 --- a/scripts/host/configure_php_storm.sh +++ b/scripts/host/configure_php_storm.sh @@ -2,7 +2,7 @@ cd "$(dirname "${BASH_SOURCE[0]}")/../.." && vagrant_dir=$PWD -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" status "Configuring PhpStorm" incrementNestingLevel @@ -17,11 +17,11 @@ enabled_virtual_host_config="/etc/apache2/sites-available/magento2.conf" host_os="$(bash "${vagrant_dir}/scripts/host/get_host_os.sh")" if [[ ${host_os} == "Windows" ]] || [[ $(bash "${vagrant_dir}/scripts/get_config_value.sh" "guest_use_nfs") == 0 ]]; then - sed -i.back "s||/var/www/magento2ce|g" "${vagrant_dir}/.idea/deployment.xml" + sed -i.back "s||/var/www/magento|g" "${vagrant_dir}/.idea/deployment.xml" sed -i.back 's|| autoUpload="Always" autoUploadExternalChanges="true"|g' "${vagrant_dir}/.idea/deployment.xml" sed -i.back 's|| @@ -17,7 +17,7 @@ diff --git a/scripts/host/php-storm-configs/php.xml b/scripts/host/php-storm-configs/php.xml index a7f4c8a8..be351a32 100644 --- a/scripts/host/php-storm-configs/php.xml +++ b/scripts/host/php-storm-configs/php.xml @@ -2,17 +2,17 @@ - + - + - + diff --git a/scripts/host/php-storm-configs/vcs.ce.xml b/scripts/host/php-storm-configs/vcs.ce.xml index 881aeb9d..520adcde 100644 --- a/scripts/host/php-storm-configs/vcs.ce.xml +++ b/scripts/host/php-storm-configs/vcs.ce.xml @@ -1,6 +1,6 @@ - + - \ No newline at end of file + diff --git a/scripts/host/php-storm-configs/vcs.ee.xml b/scripts/host/php-storm-configs/vcs.ee.xml index 8a8d4423..ce2acc8a 100644 --- a/scripts/host/php-storm-configs/vcs.ee.xml +++ b/scripts/host/php-storm-configs/vcs.ee.xml @@ -1,7 +1,7 @@ - - + + - \ No newline at end of file + diff --git a/scripts/host/php-storm-configs/vcs.xml b/scripts/host/php-storm-configs/vcs.xml index 8a8d4423..ce2acc8a 100644 --- a/scripts/host/php-storm-configs/vcs.xml +++ b/scripts/host/php-storm-configs/vcs.xml @@ -1,7 +1,7 @@ - - + + - \ No newline at end of file + diff --git a/scripts/host/relink_sample_data.sh b/scripts/host/relink_sample_data.sh old mode 100644 new mode 100755 index 6fd36d43..5d90ce10 --- a/scripts/host/relink_sample_data.sh +++ b/scripts/host/relink_sample_data.sh @@ -2,9 +2,9 @@ cd "$(dirname "${BASH_SOURCE[0]}")/../.." && vagrant_dir=$PWD -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" -magento_ce_dir="${vagrant_dir}/magento2ce" +magento_ce_dir="${vagrant_dir}/magento" magento_ee_dir="${magento_ce_dir}/magento2ee" magento_ce_sample_data_dir="${magento_ce_dir}/magento2ce-sample-data" magento_ee_sample_data_dir="${magento_ce_dir}/magento2ee-sample-data" diff --git a/scripts/host/warm_up_cache.sh b/scripts/host/warm_up_cache.sh index b1cf39f3..fe69c855 100755 --- a/scripts/host/warm_up_cache.sh +++ b/scripts/host/warm_up_cache.sh @@ -2,9 +2,9 @@ cd "$(dirname "${BASH_SOURCE[0]}")/../.." && vagrant_dir=$PWD -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" cd "${vagrant_dir}" -vagrant ssh -c "bash /vagrant/scripts/guest/warm_up_cache" 2> >(logError) +executeInMagento2Container "${vagrant_dir}/scripts/guest/warm_up_cache" 2> >(logError) # Explicit exit is necessary to bypass incorrect output from vagrant in case of errors exit 0 diff --git a/scripts/provision/configure_environment.sh b/scripts/provision/configure_environment.sh index 83a83c88..a1cea5e4 100755 --- a/scripts/provision/configure_environment.sh +++ b/scripts/provision/configure_environment.sh @@ -7,9 +7,9 @@ use_php7=$4 host_magento_dir=$5 is_windows_host=$6 -vagrant_dir="/vagrant" +vagrant_dir="${vagrant_dir}" -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" status "Configuring environment" incrementNestingLevel @@ -35,11 +35,11 @@ status "Configuring composer" composer_auth_json="${vagrant_dir}/etc/composer/auth.json" if [[ -f ${composer_auth_json} ]]; then status "Installing composer OAuth tokens from ${composer_auth_json}" - if [[ ! -d /home/vagrant/.composer ]] ; then - sudo -H -u vagrant bash -c 'mkdir /home/vagrant/.composer' 2> >(logError) > >(log) + if [[ ! -d /home${vagrant_dir}/.composer ]] ; then + sudo -H -u vagrant bash -c 'mkdir /home${vagrant_dir}/.composer' 2> >(logError) > >(log) fi if [[ -f ${composer_auth_json} ]]; then - cp "${composer_auth_json}" "/home/vagrant/.composer/auth.json" + cp "${composer_auth_json}" "/home${vagrant_dir}/.composer/auth.json" fi fi diff --git a/scripts/provision/configure_environment_recurring.sh b/scripts/provision/configure_environment_recurring.sh index 63e234e5..6a44c0f2 100755 --- a/scripts/provision/configure_environment_recurring.sh +++ b/scripts/provision/configure_environment_recurring.sh @@ -45,9 +45,9 @@ if [[ -z ${php_version} ]]; then fi -vagrant_dir="/vagrant" +vagrant_dir="${vagrant_dir}" -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" status "Configuring environment (recurring)" incrementNestingLevel @@ -66,7 +66,7 @@ update-rc.d unlink-configs defaults 04 2> >(log) > >(log) status "Upgrading existing environment" if [[ -f "${vagrant_dir}/.idea/deployment.xml" ]]; then - sed -i.back "s|magento2ce/var/generation|magento2ce/var|g" "${vagrant_dir}/.idea/deployment.xml" + sed -i.back "s|magento/var/generation|magento/var|g" "${vagrant_dir}/.idea/deployment.xml" fi status "Copying varnish vcl file" @@ -111,7 +111,7 @@ php_ini_file="/etc/php/${php_version}/cli/php.ini" pattern=";sendmail_path" php_config_content="$(cat ${php_ini_file})" if [[ ${php_config_content} =~ ${pattern} ]]; then - sed -i "s|;sendmail_path =|sendmail_path = \"/vagrant/scripts/guest/log_email ${vagrant_dir}/log/email\"|g" ${php_ini_file} + sed -i "s|;sendmail_path =|sendmail_path = \"${vagrant_dir}/scripts/guest/log_email ${vagrant_dir}/log/email\"|g" ${php_ini_file} service apache2 restart 2> >(logError) > >(log) fi diff --git a/scripts/provision/export_env_variables_recurring.sh b/scripts/provision/export_env_variables_recurring.sh index 70486bb9..9f02c8be 100755 --- a/scripts/provision/export_env_variables_recurring.sh +++ b/scripts/provision/export_env_variables_recurring.sh @@ -8,7 +8,7 @@ is_windows_host=$6 host_vagrant_dir=$7 vagrant_dir="/vagrant" -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" status "Exporting environment variables" incrementNestingLevel diff --git a/scripts/provision/upgrade_environment_recurring.sh b/scripts/provision/upgrade_environment_recurring.sh index a6d4b171..44dad529 100755 --- a/scripts/provision/upgrade_environment_recurring.sh +++ b/scripts/provision/upgrade_environment_recurring.sh @@ -12,7 +12,7 @@ function isServiceAvailable() { use_php7=$4 vagrant_dir="/vagrant" -source "${vagrant_dir}/scripts/output_functions.sh" +source "${vagrant_dir}/scripts/functions.sh" status "Upgrading environment (recurring)" incrementNestingLevel