Skip to content

Commit

Permalink
Docker added
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyb10101 committed Sep 10, 2021
1 parent cafa967 commit 12565f7
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/dist
/node_modules
/yarn-error.log
/.env
/.idea
30 changes: 30 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: '3.8'

services:
web:
image: cyb10101/php-dev:apache-8.0
hostname: sound-board
volumes:
- .:/app
- /var/run/docker.sock:/var/run/docker.sock:ro
- ~/.ssh:/home/application/.ssh:ro
- ~/.composer/cache:/home/application/.composer/cache
- ~/.gitconfig:/home/application/.gitconfig:ro

#- /tmp/.X11-unix:/tmp/.X11-unix
environment:
#- DISPLAY=${DISPLAY}
- WEB_DOCUMENT_ROOT=/app/public
working_dir: /app

node:
image: node:lts
volumes:
- ./:/app
working_dir: /app
command: tail -f /dev/null

networks:
default:
external:
name: global
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
"build:dev": "webpack --mode=development --watch",
"start": "electron .",
"start:dev": "APP_ENV=dev electron .",
"starthost": "./node_modules/electron/dist/electron .",
"starthost:dev": "APP_ENV=dev ./node_modules/electron/dist/electron .",
"dist": "electron-builder",
"dist:dev": "electron-builder --linux AppImage --x64",
"dist:mac": "electron-builder --mac",
Expand Down
185 changes: 185 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
#!/usr/bin/env bash

SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
cd "${SCRIPTPATH}"

APPLICATION_UID=${APPLICATION_UID:-1000}
APPLICATION_GID=${APPLICATION_GID:-1000}
APPLICATION_USER=${APPLICATION_USER:-application}
APPLICATION_GROUP=${APPLICATION_GROUP:-application}

loadEnvironmentVariables() {
if [ -f ".env" ]; then
source .env
fi
if [ -f ".env.local" ]; then
source .env.local
fi
}

setDockerComposeFile() {
DOCKER_COMPOSE_FILE=docker-compose.yml

# Symfony
APP_ENV=${APP_ENV:-}
if [ "${APP_ENV}" == "dev" ]; then
DOCKER_COMPOSE_FILE=docker-compose.dev.yml
fi

# TYPO3
TYPO3_CONTEXT=${TYPO3_CONTEXT:-}
if [ "${TYPO3_CONTEXT:0:11}" == "Development" ]; then
DOCKER_COMPOSE_FILE=docker-compose.dev.yml
fi

# TYPO3
WP_ENVIRONMENT_TYPE=${WP_ENVIRONMENT_TYPE:-}
if [ "${WP_ENVIRONMENT_TYPE:0:11}" == "development" ]; then
DOCKER_COMPOSE_FILE=docker-compose.dev.yml
fi

# Custom
ENV_DOCKER_CONTEXT=${ENV_DOCKER_CONTEXT:-}
if [ "${ENV_DOCKER_CONTEXT:0:11}" == "Development" ]; then
DOCKER_COMPOSE_FILE=docker-compose.dev.yml
fi
}

dockerComposeCmd() {
docker-compose -f "${DOCKER_COMPOSE_FILE}" "${@:1}"
}

checkRoot() {
if [[ $EUID -ne 0 ]]; then
echo 'You must be a root user!' 2>&1
exit 1
fi
}

gitCheckBranch() {
if [ -d ".git" ]; then
if [[ $(git symbolic-ref --short -q HEAD) != "${1}" ]]; then
echo "ERROR: Git is not on branch ${1}!"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
fi
fi
}

gitCheckDirty() {
if [ -d ".git" ]; then
if [[ $(git diff --stat) != '' ]]; then
echo
git status --porcelain
echo

read -p 'Git is dirty... Continue? [y/N] ' -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
fi
fi
fi
}

setPermissions() {
chown -R ${APPLICATION_UID}:${APPLICATION_GID} .
find . -type d -exec chmod ugo+rx,ug+w {} \;
find . -type f -exec chmod ugo+r,ug+w {} \;
}

gitPullHost() {
if [ -d ".git" ]; then
git pull "${@:1}"
fi
}

gitPullGuest() {
if [ -d ".git" ]; then
startFunction exec-web git pull "${@:1}"
fi
}

composerInstall() {
if [ -f "composer.json" ]; then
startFunction exec-web composer install "${@:1}"
fi
}

symfonyUpdateDatabase() {
if [ -f "symfony.lock" ]; then
read -p 'Update database schema? [y/N] ' -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
startFunction exec-web ./bin/console doctrine:schema:update --force
fi
fi
}

symfonyClearCache() {
if [ -f "symfony.lock" ]; then
startFunction exec-web ./bin/console cache:clear --no-warmup
startFunction exec-web ./bin/console cache:warmup
fi
}

runDeploy() {
gitPullHost origin ${GIT_BRANCH}
setPermissions

# Git: Deploy as user in container (SSH-Key for private repositories needed)
#gitPullGuest origin ${GIT_BRANCH}

# Deploy as user in container
startFunction start
composerInstall

#symfonyUpdateDatabase
symfonyClearCache
}

loadEnvironmentVariables
GIT_BRANCH="${GIT_BRANCH:-master}"
setDockerComposeFile

startFunction() {
case ${1} in
start)
startFunction pull && \
startFunction build && \
startFunction up
;;
up)
dockerComposeCmd up -d
;;
down)
dockerComposeCmd down --remove-orphans
;;
login-root)
dockerComposeCmd exec web bash
;;
login)
startFunction bash
;;
bash)
dockerComposeCmd exec -u ${APPLICATION_USER} web bash
;;
zsh)
dockerComposeCmd exec -u ${APPLICATION_USER} web zsh
;;
exec-web)
dockerComposeCmd exec -u ${APPLICATION_USER} web "${@:2}"
;;
deploy)
checkRoot
gitCheckBranch ${GIT_BRANCH}
gitCheckDirty
runDeploy
;;
*)
dockerComposeCmd "${@:1}"
;;
esac
}

startFunction "${@:1}"
exit $?

0 comments on commit 12565f7

Please sign in to comment.