Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from edustripetech/ch-docker-setup
Ch docker setup
- Loading branch information
Showing
18 changed files
with
1,165 additions
and
9,456 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,3 +63,6 @@ typings/ | |
# VSCode config files | ||
.vscode/ | ||
*.code-workspace | ||
|
||
# Backups | ||
db-backup/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM node:13-alpine | ||
MAINTAINER EdustripeDev <edustripedev@gmail.com> | ||
# Update and install packages | ||
RUN apk update | ||
RUN apk add --update git zip vim wget unzip curl nginx python3 py3-pip yarn bash | ||
|
||
# Install awscli using pip | ||
RUN pip3 install awscli --upgrade | ||
|
||
# prepare a user which runs everything locally! | ||
RUN adduser --disabled-password -s /bin/bash edustripe | ||
|
||
COPY ./arch/scripts/entrypoint.sh /usr/local/bin/entrypoint.sh | ||
COPY ./arch/scripts/repo.sh /usr/local/bin/repo.sh | ||
|
||
RUN chmod +x /usr/local/bin/repo.sh && chmod +x /usr/local/bin/entrypoint.sh | ||
|
||
#set the terminal to xterm | ||
RUN export TERM=xterm | ||
|
||
WORKDIR /var/www | ||
|
||
CMD ["entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
module.exports = { | ||
up: (queryInterface, Sequelize) => queryInterface.createTable('Credentials', { | ||
id: { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
server { | ||
listen 80; | ||
location / { | ||
proxy_set_header Upgrade $http_upgrade; | ||
proxy_set_header Connection 'upgrade'; | ||
proxy_set_header Host $host; | ||
proxy_cache_bypass $http_upgrade; | ||
proxy_http_version 1.1; | ||
proxy_pass http://127.0.0.1:5000/; | ||
} | ||
|
||
# Block all git access | ||
if ($request_uri ~* ^.*\.git.*$) { | ||
return 404; | ||
} | ||
|
||
# Enable Gzip for | ||
gzip on; | ||
gzip_http_version 1.1; | ||
gzip_vary on; | ||
gzip_comp_level 6; | ||
gzip_proxied any; | ||
gzip_types image/jpeg image/png text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js; | ||
gzip_min_length 70000; | ||
gunzip on; | ||
gzip_buffers 16 8k; | ||
gzip_disable "MSIE [1-6]\.(?!.*SV1)"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CREATE DATABASE edustripe_account_test | ||
WITH | ||
OWNER = edustripe | ||
ENCODING = 'UTF8' | ||
LC_COLLATE = 'en_US.utf8' | ||
LC_CTYPE = 'en_US.utf8' | ||
TABLESPACE = pg_default | ||
CONNECTION LIMIT = -1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env bash | ||
|
||
export WORKING_DIR=/var/www | ||
export APP_WORKSPACE=${APP_WORKSPACE:-$APP_NAME} | ||
export APP_ENV=${APP_ENV:-local} | ||
|
||
echo ">>Preparing app $APP_NAME..." | ||
echo ">>APP_ENV: $APP_ENV" | ||
|
||
if [[ $APP_ENV != "local" && $APP_ENV != "test" ]]; then | ||
# Download and setup repository if not in local environment | ||
source repo.sh init | ||
fi | ||
|
||
#Change directory to APP_WORKSPACE | ||
cd "$WORKING_DIR/$APP_WORKSPACE" || exit 1 | ||
|
||
#Install dependencies | ||
echo ">>Running yarn to install or update dependencies..." | ||
yarn | ||
|
||
if [ $APP_ENV == "test" ]; then | ||
chmod +x "$WORKING_DIR/$APP_WORKSPACE/arch/scripts/run-test.sh" | ||
source "$WORKING_DIR/$APP_WORKSPACE/arch/scripts/run-test.sh" || exit 1 | ||
echo ">>Test ran successfully";exit 0 | ||
else | ||
#Do any necessary setup Move this back | ||
chmod +x "$WORKING_DIR/$APP_WORKSPACE/arch/scripts/setup.sh" | ||
source "$WORKING_DIR/$APP_WORKSPACE/arch/scripts/setup.sh" || exit 1 | ||
fi | ||
|
||
chmod +x "$WORKING_DIR/$APP_WORKSPACE/arch/scripts/start-server.sh" | ||
source "$WORKING_DIR/$APP_WORKSPACE/arch/scripts/start-server.sh" || exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
set -o pipefail | ||
|
||
GIT_OAUTH2_USER="${GIT_OAUTH2_USER:-oauth2}" | ||
GIT_BRANCH="${GIT_BRANCH:-master}" | ||
|
||
ACTION="${1:-init}" | ||
shift | ||
|
||
VALID_ACTIONS=("checkout" "pull" "clone" "reset" "status" "init") | ||
if [[ ! " ${VALID_ACTIONS[*]} " == *" $ACTION "* ]]; then | ||
printf '>>ERROR: invalid action %s \nAction is the first argument and can only be any of:\n %s\n' "$ACTION" "$(IFS=, ; echo "${VALID_ACTIONS[*]}")" >&2 | ||
exit 1 | ||
fi | ||
|
||
while :; do | ||
case $1 in | ||
-b|--branch) | ||
if [ "$2" ]; then | ||
GIT_BRANCH=$2 | ||
shift | ||
else | ||
printf 'ERROR: %s is a non-empty optional argument\n' "$1" >&2 | ||
exit 1 | ||
fi | ||
;; | ||
-u|--url) | ||
if [ "$2" ]; then | ||
FULL_GIT_URL=$2 | ||
shift | ||
else | ||
printf 'ERROR: %s is a non-empty optional argument\n' "$1" >&2 | ||
exit 1 | ||
fi | ||
;; | ||
--) # End of all options. | ||
shift | ||
break | ||
;; | ||
-?*) | ||
printf 'ERROR: Unknown option : %s\n' "$1" >&2 | ||
exit 1 | ||
;; | ||
*) # Default case: No more options, so break out of the loop. | ||
break | ||
esac | ||
shift | ||
done | ||
|
||
if [ -z "$APP_WORKSPACE" ]; then | ||
echo ">>Need to set APP_NAME env variable";exit 1 | ||
fi | ||
|
||
if [ -z "$FULL_GIT_URL" ]; then | ||
if [ -z "$REPOSITORY_URL" ]; then | ||
echo ">>Need to set REPOSITORY_URL env variable or provide -u argument" | ||
exit 1 | ||
elif [ -z "$GIT_OAUTH2_TOKEN" ]; then | ||
echo ">>Need to set GIT_OAUTH2_TOKEN env variable or provide -u argument" | ||
exit 1 | ||
else | ||
FULL_GIT_URL="https://${GIT_OAUTH2_USER}:${GIT_OAUTH2_TOKEN}@${REPOSITORY_URL}" | ||
fi | ||
fi | ||
|
||
checkout () | ||
{ | ||
if [ -d "$WORKING_DIR/$APP_WORKSPACE/.git" ]; then | ||
printf ">>Checking out to branch [%s]:\n" "$GIT_BRANCH" | ||
cd "$WORKING_DIR/$APP_WORKSPACE";git checkout $GIT_BRANCH; | ||
else | ||
printf ">>The [%s] repo is not cloned.\n" "$APP_WORKSPACE" | ||
fi | ||
} | ||
|
||
pull () | ||
{ | ||
echo ">>Changing directory to $WORKING_DIR/$APP_WORKSPACE" | ||
cd "$WORKING_DIR/$APP_WORKSPACE" || exit 1 | ||
echo ">>Pulling latest changes from branch $GIT_BRANCH into $WORKING_DIR/$APP_WORKSPACE" | ||
git pull $FULL_GIT_URL $GIT_BRANCH | ||
checkout | ||
} | ||
|
||
clone () | ||
{ | ||
echo ">>Changing directory to $WORKING_DIR" | ||
cd $WORKING_DIR; | ||
echo ">>Cloning fresh repository..." | ||
git clone $FULL_GIT_URL "$WORKING_DIR/$APP_WORKSPACE" | ||
if [ -d "$WORKING_DIR/$APP_WORKSPACE/.git" ]; then | ||
echo ">>Successfull clone $REPOSITORY_URL" | ||
checkout | ||
else | ||
echo ">>Error occurred, could not clone $REPOSITORY_URL, Exiting..." | ||
exit 1 | ||
fi | ||
} | ||
|
||
init () | ||
{ | ||
if [ -d "$WORKING_DIR/$APP_WORKSPACE" ]; then | ||
if [ -d "$WORKING_DIR/$APP_WORKSPACE/.git" ]; then | ||
echo ">>Repository $REPOSITORY_URL already exist" | ||
pull | ||
else | ||
echo ">>Workspace $APP_WORKSPACE already exist but not a git repository; removing old Workspace." | ||
rm -fr "$WORKING_DIR/$APP_WORKSPACE" | ||
clone | ||
fi | ||
else | ||
clone | ||
fi | ||
} | ||
|
||
reset () | ||
{ | ||
cd "$WORKING_DIR/$APP_WORKSPACE" || echo ">>Directory $WORKING_DIR/$APP_WORKSPACE does not exits" && exit 1 | ||
git reset --hard HEAD | ||
git checkout $GIT_BRANCH | ||
git reset --hard "origin/$GIT_BRANCH" | ||
git pull | ||
} | ||
|
||
status () | ||
{ | ||
if [ -d "$WORKING_DIR/$APP_WORKSPACE/.git" ]; then | ||
printf ">>Git status for [%s]:\n" "$APP_WORKSPACE" | ||
cd "$WORKING_DIR/$APP_WORKSPACE";git status; | ||
else | ||
printf "The [%s] repo is not cloned.\n" "$APP_WORKSPACE" | ||
fi | ||
} | ||
|
||
if [ "$ACTION" == "checkout" ]; then | ||
checkout | ||
elif [ "$ACTION" == "clone" ]; then | ||
clone | ||
elif [ "$ACTION" == "pull" ]; then | ||
pull | ||
elif [ "$ACTION" == "reset" ]; then | ||
read -p ">>This will override any uncommited changes in your local git checkouts. Would you like to proceed? [y/n] " -r | ||
if [[ $REPLY =~ ^[Yy]$ ]]; then | ||
reset | ||
fi | ||
elif [ "$ACTION" == "status" ]; then | ||
status | ||
elif [ "$ACTION" == "init" ]; then | ||
init | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
set -o pipefail | ||
|
||
if [ "$TEST_ONLY" == "1" ]; then | ||
echo ">>Running test with 'yarn test:all'..." | ||
yarn test:all | ||
else | ||
echo ">>Running lint with 'yarn lint'..." | ||
yarn lint | ||
echo ">>Build app 'yarn build'..." | ||
yarn build | ||
echo ">>Running test with 'yarn test'..." | ||
yarn test | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
set -o pipefail | ||
|
||
if [ "$APP_ENV" != "local" ]; then | ||
#Update nginx config and start it if not on local environment | ||
echo ">>Copying nginx configuration..." | ||
cat "$WORKING_DIR/$APP_WORKSPACE/arch/conf.d/$APP_ENV.conf" > /etc/nginx/conf.d/default.conf | ||
echo ">>Starting nginx..." | ||
nginx || exit 1 | ||
|
||
## Copy environment file | ||
cp ".env.$APP_ENV" ".env" | ||
fi | ||
|
||
if [ "$UNDO_MIGRATION_ON_STARTUP" == 1 ]; then | ||
echo ">>Undoing database migrations..." | ||
yarn db:migrate:undo | ||
fi | ||
|
||
#Run migrations | ||
echo ">>Running database migrations..." | ||
yarn db:migrate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
set -o pipefail | ||
|
||
if [ $APP_ENV == "local" ]; then | ||
echo ">>Running local server..." | ||
yarn dev | ||
else | ||
# Build and run server | ||
echo ">>Building app with 'yarn build...'" | ||
yarn build | ||
echo "Starting $APP_ENV server..." | ||
yarn start | ||
fi |
Oops, something went wrong.