diff --git a/.github/workflows/buildReleaseImagesAndDoRelease.yml b/.github/workflows/buildReleaseImagesAndDoRelease.yml index a89ddf6..5935f4a 100644 --- a/.github/workflows/buildReleaseImagesAndDoRelease.yml +++ b/.github/workflows/buildReleaseImagesAndDoRelease.yml @@ -12,7 +12,7 @@ jobs: - name: Build php-fpm image run: docker build -f ./docker/php-fpm/Dockerfile-test -t php-fpm-for-tests:test . - name: Start php-fpm container - run: docker run -d --name testContainer -v "/home/runner/work/symfony-docker/symfony-docker/app":"/var/www" php-fpm-for-tests:test + run: docker run -d --name testContainer -v "/home/runner/work/${GITHUB_REPOSITORY#*/}/${GITHUB_REPOSITORY#*/}/app":"/var/www" php-fpm-for-tests:test - name: Prepare container run: docker exec testContainer composer install - name: Run PHPUnit diff --git a/.github/workflows/buildVersionImages.yml b/.github/workflows/buildVersionImages.yml index 3797c95..e2e548c 100644 --- a/.github/workflows/buildVersionImages.yml +++ b/.github/workflows/buildVersionImages.yml @@ -12,7 +12,7 @@ jobs: - name: Build php-fpm image run: docker build -f ./docker/php-fpm/Dockerfile-test -t php-fpm-for-tests:test . - name: Start php-fpm container - run: docker run -d --name testContainer -v "/home/runner/work/symfony-docker/symfony-docker/app":"/var/www" php-fpm-for-tests:test + run: docker run -d --name testContainer -v "/home/runner/work/${GITHUB_REPOSITORY#*/}/${GITHUB_REPOSITORY#*/}/app":"/var/www" php-fpm-for-tests:test - name: Prepare container run: docker exec testContainer composer install - name: Run PHPUnit diff --git a/.github/workflows/runAllTests.yml b/.github/workflows/runAllTests.yml index 862e9d2..fa4f32e 100644 --- a/.github/workflows/runAllTests.yml +++ b/.github/workflows/runAllTests.yml @@ -16,7 +16,7 @@ jobs: - name: Build php-fpm image run: docker build -f ./docker/php-fpm/Dockerfile-test -t php-fpm-for-tests:test . - name: Start php-fpm container - run: docker run -d --name testContainer -v "/home/runner/work/symfony-docker/symfony-docker/app":"/var/www" php-fpm-for-tests:test + run: docker run -d --name testContainer -v "/home/runner/work/${GITHUB_REPOSITORY#*/}/${GITHUB_REPOSITORY#*/}/app":"/var/www" php-fpm-for-tests:test - name: Prepare container run: docker exec testContainer composer install - name: Run PHPUnit diff --git a/README.md b/README.md index c684545..7444775 100644 --- a/README.md +++ b/README.md @@ -75,8 +75,22 @@ Your images you can find on your github profile under "Packages" tab. |CR_PAT| with token for image repository (from previous step) | ## Init production +### Set Kubernetes namespace +All configs use namespace attribute. Namespace is generated from your github +username/repo (repo must be cloned with git), for example: +```sh +Repo: git@github.com:kdosiodjinud/symfony-docker.git +Generated namespace: kdosiodjinud-symfony-docker +``` + +Becouse project is universal, you must init script for replace namespaces in your cloned version: +```sh +./cli init +``` +That`s all! :) + ### Services -Look at the kubernetes/init/secrets.yaml file and config your settings for production. +Look at the **kubernetes/init/secrets.yaml** file and config your settings for production. After check apply configure all files from folder init: ```sh diff --git a/cli-src/cli b/cli-src/cli index ea0a73e..8abb43c 100755 --- a/cli-src/cli +++ b/cli-src/cli @@ -28,6 +28,7 @@ cli_usage() { echo " start Start application containers" echo " stop Stop application containers" echo " tests Run test in PHP container" + echo " init Update config files for your settings (dependent to .git and github repository)" echo if [[ -n $long_usage ]]; then @@ -179,6 +180,31 @@ cli_tests_usage() { fi } +# :command.usage +cli_init_usage() { + if [[ -n $long_usage ]]; then + printf "cli init - Update config files for your settings (dependent to .git and github repository)\n" + echo + else + printf "cli init - Update config files for your settings (dependent to .git and github repository)\n" + echo + fi + + printf "Usage:\n" + printf " cli init\n" + printf " cli init --help | -h\n" + echo + + if [[ -n $long_usage ]]; then + printf "Options:\n" + # :command.usage_fixed_flags + echo " --help, -h" + printf " Show this help\n" + echo + + fi +} + # :command.inspect_args inspect_args() { echo args: @@ -235,6 +261,16 @@ cli_tests_command() { esac } +# :command.function +cli_init_command() { + # :src/init_command.sh + GIT_REPO_NAME=$(cut -d ":" -f2 <<< $(git config --get remote.origin.url)) + REPO_NAME=${GIT_REPO_NAME/.git/} + APP_NAMESPACE=${REPO_NAME/\//-} + + find ./kubernetes/ -type f -exec sed -i '' -e "s/#{APP_NAMESPACE}#/$APP_NAMESPACE/g" {} \; +} + # :command.parse_requirements parse_requirements() { # :command.fixed_flag_filter @@ -288,6 +324,13 @@ parse_requirements() { shift $# ;; + init ) + action="init" + shift + cli_init_parse_requirements "$@" + shift $# + ;; + * ) cli_usage exit 1 @@ -495,6 +538,49 @@ cli_tests_parse_requirements() { [[ -n ${args[type]} ]] || args[type]="all" } +# :command.parse_requirements +cli_init_parse_requirements() { + # :command.fixed_flag_filter + case "$1" in + --version | -v ) + version_command + exit + ;; + + --help | -h ) + long_usage=yes + cli_init_usage + exit 1 + ;; + + esac + # :command.environment_variables_filter + # :command.dependencies_filter + # :command.command_filter + action="init" + # :command.required_args_filter + # :command.required_flags_filter + # :command.parse_requirements_while + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + + -* ) + printf "invalid option: %s\n" "$key" + exit 1 + ;; + + * ) + # :command.parse_requirements_case + printf "invalid argument: %s\n" "$key" + exit 1 + ;; + + esac + done + # :command.default_assignments +} + # :command.initialize initialize() { version="0.0.1" @@ -547,6 +633,14 @@ run() { cli_tests_command fi + elif [[ $action == "init" ]]; then + if [[ ${args[--help]} ]]; then + long_usage=yes + cli_init_usage + else + cli_init_command + fi + elif [[ ${args[--version]} ]]; then version_command elif [[ ${args[--help]} ]]; then diff --git a/cli-src/src/bashly.yml b/cli-src/src/bashly.yml index a2eda92..71612fa 100644 --- a/cli-src/src/bashly.yml +++ b/cli-src/src/bashly.yml @@ -27,5 +27,7 @@ commands: - cli tests phpstan - cli tests phpunit - cli tests ecs +- name: init + help: Update config files for your settings (dependent to .git and github repository) diff --git a/cli-src/src/init_command.sh b/cli-src/src/init_command.sh new file mode 100644 index 0000000..c4cca2e --- /dev/null +++ b/cli-src/src/init_command.sh @@ -0,0 +1,5 @@ +GIT_REPO_NAME=$(cut -d ":" -f2 <<< $(git config --get remote.origin.url)) +REPO_NAME=${GIT_REPO_NAME/.git/} +APP_NAMESPACE=${REPO_NAME/\//-} + +find ./kubernetes/ -type f -exec sed -i '' -e "s/#{APP_NAMESPACE}#/$APP_NAMESPACE/g" {} \; diff --git a/kubernetes/ingress/cert.yaml b/kubernetes/ingress/cert.yaml index a9bece5..57cd973 100644 --- a/kubernetes/ingress/cert.yaml +++ b/kubernetes/ingress/cert.yaml @@ -6,7 +6,7 @@ metadata: name: letsencrypt-prod spec: acme: - email: jankuthan@email.cz + email: REPLACE_WITH_@_YOUR_EMAIL.COM privateKeySecretRef: name: letsencrypt-prod server: https://acme-v02.api.letsencrypt.org/directory diff --git a/kubernetes/ingress/ingress.yaml b/kubernetes/ingress/ingress.yaml index 6371bd3..97e18af 100644 --- a/kubernetes/ingress/ingress.yaml +++ b/kubernetes/ingress/ingress.yaml @@ -2,7 +2,7 @@ apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: ingress-wildcard-host - namespace: symfony + namespace: #{APP_NAMESPACE}# annotations: kubernetes.io/ingress.class: nginx kubernetes.io/tls-acme: "true" @@ -10,7 +10,7 @@ metadata: nginx.ingress.kubernetes.io/actions.ssl-redirect: '{"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}' spec: rules: - - host: "vps.reddwarf.cloud" + - host: "REPLACE.IT.WITH_YOUR_DOMAIN.COM" http: paths: - pathType: Prefix @@ -23,4 +23,4 @@ spec: tls: - secretName: symfony-tls-cert hosts: - - vps.reddwarf.cloud + - REPLACE.IT.WITH_YOUR_DOMAIN.COM diff --git a/kubernetes/init/apache_service.yaml b/kubernetes/init/apache_service.yaml index 4d783c1..6c8326f 100644 --- a/kubernetes/init/apache_service.yaml +++ b/kubernetes/init/apache_service.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: Service metadata: name: apache - namespace: symfony + namespace: #{APP_NAMESPACE}# spec: selector: app: apache diff --git a/kubernetes/init/php_service.yaml b/kubernetes/init/php_service.yaml index ff912d1..3fdca50 100644 --- a/kubernetes/init/php_service.yaml +++ b/kubernetes/init/php_service.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: Service metadata: name: php-fpm - namespace: symfony + namespace: #{APP_NAMESPACE}# spec: selector: app: php-fpm diff --git a/kubernetes/init/secrets.yaml b/kubernetes/init/secrets.yaml index 9e494c9..d367d84 100644 --- a/kubernetes/init/secrets.yaml +++ b/kubernetes/init/secrets.yaml @@ -1,10 +1,10 @@ apiVersion: v1 kind: Secret metadata: - name: symfony-secrets - namespace: symfony + name: app-secrets + namespace: #{APP_NAMESPACE}# data: - EXAMPLE_VARIABLE_IN_BASE64: MjRlMTdjNDc0MzBiZDIwNDRhNjFjMTMxYzFjZjY5OTAK + EXAMPLE_VARIABLE_IN_BASE64: EXAMPLEVALUE= stringData: - DATABASE_URL: 'postgres://vxlsmawa:v9yqR2V3yYV1lk3OIyd6nD6Hu2Bbs_0s@hattie.db.elephantsql.com:5432/vxlsmawa' - APP_SECRET: '24e17c47430bd2044a61c131c1cf6990' + DATABASE_URL: 'postgres://USERNAME:PASSWORD@HOSTNAME:PORT/DATABASE' + APP_SECRET: '123456789_APP_SECRET_EXAMPLE' diff --git a/kubernetes/release/apache_deployment.yaml b/kubernetes/release/apache_deployment.yaml index bd6a742..47af3aa 100644 --- a/kubernetes/release/apache_deployment.yaml +++ b/kubernetes/release/apache_deployment.yaml @@ -2,7 +2,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: apache - namespace: symfony + namespace: #{APP_NAMESPACE}# labels: app: apache spec: diff --git a/kubernetes/release/php_deployment.yaml b/kubernetes/release/php_deployment.yaml index bd2469c..719a236 100644 --- a/kubernetes/release/php_deployment.yaml +++ b/kubernetes/release/php_deployment.yaml @@ -2,7 +2,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: php-fpm - namespace: symfony + namespace: #{APP_NAMESPACE}# labels: app: php-fpm spec: @@ -20,7 +20,7 @@ spec: image: #{IMAGE_PHP_FPM}# envFrom: - secretRef: - name: symfony-secrets + name: app-secrets imagePullPolicy: Always ports: - containerPort: 9000