Skip to content

Commit

Permalink
Universal variables for sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Kuthan committed Dec 10, 2020
1 parent 60f3157 commit 3291317
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/buildReleaseImagesAndDoRelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/buildVersionImages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/runAllTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]: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
Expand Down
94 changes: 94 additions & 0 deletions cli-src/cli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -288,6 +324,13 @@ parse_requirements() {
shift $#
;;

init )
action="init"
shift
cli_init_parse_requirements "$@"
shift $#
;;

* )
cli_usage
exit 1
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cli-src/src/bashly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)


5 changes: 5 additions & 0 deletions cli-src/src/init_command.sh
Original file line number Diff line number Diff line change
@@ -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" {} \;
2 changes: 1 addition & 1 deletion kubernetes/ingress/cert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
name: letsencrypt-prod
spec:
acme:
email: [email protected]
email: REPLACE_WITH_@_YOUR_EMAIL.COM
privateKeySecretRef:
name: letsencrypt-prod
server: https://acme-v02.api.letsencrypt.org/directory
Expand Down
6 changes: 3 additions & 3 deletions kubernetes/ingress/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ 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"
cert-manager.io/cluster-issuer: "letsencrypt-prod"
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
Expand All @@ -23,4 +23,4 @@ spec:
tls:
- secretName: symfony-tls-cert
hosts:
- vps.reddwarf.cloud
- REPLACE.IT.WITH_YOUR_DOMAIN.COM
2 changes: 1 addition & 1 deletion kubernetes/init/apache_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: apache
namespace: symfony
namespace: #{APP_NAMESPACE}#
spec:
selector:
app: apache
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/init/php_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: php-fpm
namespace: symfony
namespace: #{APP_NAMESPACE}#
spec:
selector:
app: php-fpm
Expand Down
10 changes: 5 additions & 5 deletions kubernetes/init/secrets.yaml
Original file line number Diff line number Diff line change
@@ -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:[email protected]:5432/vxlsmawa'
APP_SECRET: '24e17c47430bd2044a61c131c1cf6990'
DATABASE_URL: 'postgres://USERNAME:PASSWORD@HOSTNAME:PORT/DATABASE'
APP_SECRET: '123456789_APP_SECRET_EXAMPLE'
2 changes: 1 addition & 1 deletion kubernetes/release/apache_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: apache
namespace: symfony
namespace: #{APP_NAMESPACE}#
labels:
app: apache
spec:
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/release/php_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: php-fpm
namespace: symfony
namespace: #{APP_NAMESPACE}#
labels:
app: php-fpm
spec:
Expand All @@ -20,7 +20,7 @@ spec:
image: #{IMAGE_PHP_FPM}#
envFrom:
- secretRef:
name: symfony-secrets
name: app-secrets
imagePullPolicy: Always
ports:
- containerPort: 9000
Expand Down

0 comments on commit 3291317

Please sign in to comment.