Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ The following stacks are currently supported
- Django
- React JS
- Node JS
- Next JS
- PHP
- Static HTML

Expand Down Expand Up @@ -103,6 +104,9 @@ sh install.sh python /path/to/django/project
# or for a reactjs project
sh install.sh reactjs /path/to/reactjs/project

# or for a nextjs project
sh install.sh nextjs /path/to/nextjs/project

# or for a node project
sh install.sh node /path/to/node/project

Expand Down Expand Up @@ -130,6 +134,9 @@ deploy --install python /path/to/django/project
# or for a reactjs project
deploy --install reactjs /path/to/reactjs/project

# or for a nextjs project
deploy --install nextjs /path/to/nextjs/project

# or for a node project
deploy --install node /path/to/node/project

Expand Down Expand Up @@ -188,7 +195,7 @@ It can also use the commented out optional files that are listed, but will work
All projects must have the following vars defined (in app-config.sh or config.sh) so that the relevant steps are executed.

```bash
# The project type. Currently supported options are: java, rails, python, node, and reactjs
# The project type. Currently supported options are: java, rails, python, node, reactjs and nextjs
TYPE=rails
# The name that will be used to label the app that is being deployed, commonly the hostname where the service is made available is used
SERVICE_NAME=service.com
Expand Down Expand Up @@ -294,6 +301,8 @@ sh tests/java.sh
sh tests/rails.sh
# Test React JS deployment
sh tests/reactjs.sh
# Test Next JS deployment
sh tests/nextjs.sh
# Test Django deployment
sh tests/django.sh
# Test Static HTML and PHP website deployment
Expand Down Expand Up @@ -361,6 +370,8 @@ Currently allowed values:

- `reactjs`

- `nextjs`

- `html` - for static HTML sites or simple PHP sites

### `BUILD`
Expand All @@ -371,7 +382,7 @@ Currently allowed values:

- `mvnw` - for java projects

- `npm` - for reactjs projects
- `npm` - for reactjs and nextjs projects

### `FORMAT`

Expand All @@ -389,6 +400,8 @@ Currently allowed values:

- `reactjs` - for reactjs projects

- `nextjs` - for nextjs projects

- `static` - for static HTML sites or simple PHP sites

### `REPO`
Expand Down
2 changes: 1 addition & 1 deletion deploy-scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ show_ds_usage() {

show_installer_usage() {
show_version
printf "\nUsage:\n\tdeploy-scripts.sh --install [project type] [project directory] [options]\n\nThe values for [project type] can be\n\tjava\n\trails\n\tpython\n\treactjs\n\thtml\n\tnode\n"
printf "\nUsage:\n\tdeploy-scripts.sh --install [project type] [project directory] [options]\n\nThe values for [project type] can be\n\tjava\n\trails\n\tpython\n\treactjs\n\tnextjs\n\thtml\n\tnode\n"
exit 1
}

Expand Down
3 changes: 3 additions & 0 deletions installer/upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ elif [ "$BUILD" = "python-django" ]; then
elif [ "$BUILD" = "reactjs" ]; then
TYPE="reactjs"
BUILD="npm"
elif [ "$BUILD" = "nextjs" ]; then
TYPE="nextjs"
BUILD="npm"
elif [ "$BUILD" = "rails" ]; then
TYPE="rails"
BUILD=""
Expand Down
39 changes: 39 additions & 0 deletions projects/nextjs/build/npm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
ds_build() {
if [ "$1" = "" ] || [ "$2" = "" ]; then
error "build: npm: Too few arguments given"
fi
if [ ! -d "$2" ]; then
error "build: npm: No package directory available to place warfile"
fi
cd "$1"

ENV_JS_PATH="$1/../repo/$DS_DIR/environments/$PROJECT_ENVIRONMENT/.env"
if [ ! -f "$ENV_JS_PATH" ]; then
if [ "$NEXTJS_ENVJS_PATH" != "" ]; then
CHECK_ABS_PATH=$(echo $NEXTJS_ENVJS_PATH | cut -c -1)
if [ "$CHECK_ABS_PATH" = "/" ]; then
ENV_JS_PATH="$NEXTJS_ENVJS_PATH"
else
ENV_JS_PATH="$1/../repo/$DS_DIR/$NEXTJS_ENVJS_PATH"
fi
fi
fi
if [ ! -f "$ENV_JS_PATH" ]; then
warning "No .env found at $ENV_JS_PATH. Building without it"
else
ln -s "$ENV_JS_PATH" .env
fi

if [ "$NPM_PREFIX" != "" ]; then
mkdir -p $NPM_PREFIX && ln -sf $NPM_PREFIX node_modules && npm install
else
npm install
fi
npx next build
npx next export
if [ -d "./out" ]; then
cp -r ./out/* "$2/"
else
error "NPM output directory not found under either out/"
fi
}
11 changes: 11 additions & 0 deletions projects/nextjs/format/nextjs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ds_format() {
if [ "$1" = "" ]; then
error "format: nextjs: Too few arguments given"
fi

cd "$1"

info "Preparing deployment files for packaging ... "
git --work-tree=./ --git-dir=../repo/.git checkout -f 2>&1 | indent
success 'done'
}
12 changes: 12 additions & 0 deletions projects/nextjs/installer/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ds_install () {
if [ "$1" = "" ]; then
error "installer: nextjs: Project directory not supplied"
fi

ds_create_dir_structure "$1" "$DS_DIR" "nextjs"
infof "Adding nextjs vars to app-config.sh ... "
printf "BUILD=npm\n" >> "$1/$DS_DIR/app-config.sh"
printf "LINKED_FILES=\"src/_config/env.js\"\n" >> "$1/$DS_DIR/app-config.sh"
printf "LINKED_DIRS=\"logs\"\n" >> "$1/$DS_DIR/app-config.sh"
success "done"
}
18 changes: 18 additions & 0 deletions projects/nextjs/push/git-bare/post-receive-hook
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

set -e

SCRIPT_PATH=$(dirname $(readlink -f $0))
. $SCRIPT_PATH/post-receive-utils.sh

deploy

if [ "$FORMAT" = "nextjs" ] && [ "$BUILD" = "" ]; then
title 'deploy - build'
cd $DEPLOY_DIR/current
npm install
npx next build
npx next export
fi

post_startup
9 changes: 9 additions & 0 deletions projects/nextjs/template/app-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
TYPE=nextjs
BUILD=npm
REPO=git@github.com:loanstreet/app-name.git

DEPLOYMENT_SERVER=dev-partners.loanstreet.com.my
DEPLOYMENT_SSH_USER=deploy
SERVICE_NAME=app-name
LINKED_FILES="src/_config/env.js"
LINKED_DIRS="logs"
22 changes: 22 additions & 0 deletions projects/nextjs/template/environments/default/assets/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
server {
listen 80 ;
server_name xc-test.finology.com.my;

gzip on;
gzip_http_version 1.0;
gzip_disable "msie6";
gzip_vary on;
gzip_min_length 1100;
gzip_buffers 64 8k;
gzip_comp_level 3;
gzip_proxied any;
gzip_types text/css text/xml application/x-javascript application/atom+xml text/mathml text/plain text/vnd.sun.j2me.app-descriptor text/vnd.wap.wml text/x-component;

root /home/deploy/sites/xpresscover-portal/staging/current/build;
access_log /home/deploy/sites/xpresscover-portal/staging/current/logs/nginx.access.log;
error_log /home/deploy/sites/xpresscover-portal/staging/current/logs/nginx.error.log info;

error_page 500 502 503 504 /500.html;
client_max_body_size 25M;
keepalive_timeout 10;
}
2 changes: 2 additions & 0 deletions projects/nextjs/template/environments/default/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PROJECT_ENVIRONMENT=default
GIT_BRANCH=default
56 changes: 56 additions & 0 deletions tests/nextjs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/sh

set -e

SCRIPT_PATH=$(dirname $(readlink -f $0))
. $SCRIPT_PATH/common.sh

PROJECT_FILES_DIR=nextjs-project
SRV_SCRIPT_PID=$(ps -elf | grep 'tmp-webserver.js' | grep -v grep | awk '{print $4}')
if [ "$SRV_SCRIPT_PID" != "" ]; then
printf "Killing old server.js PID: $SRV_SCRIPT_PID ... "
kill -9 $SRV_SCRIPT_PID
success 'done'
fi
copy_deployment_files 'nextjs' $SCRIPT_PATH/resources/$PROJECT_FILES_DIR

title 'TEST - editing configs'

SERVICE_NAME="nextjs-deploy-test"
PROJECT_ENVIRONMENT="default"
DEPLOYMENT_DIR="$TEST_WORKING_DIR/$SERVICE_NAME/$PROJECT_ENVIRONMENT"

cd $COPY_PROJECT_DIR/$PROJECT_FILES_DIR
PROJECT_DEPLOY_DIR="$COPY_PROJECT_DIR/nextjs-project/deploy"
printf "\nDEPLOYMENT_DIR=$DEPLOYMENT_DIR\nDEPLOYMENT_SERVER=localhost\nDEPLOYMENT_SERVER_USER=$USER\nREPO=file://$COPY_PROJECT_DIR/$PROJECT_FILES_DIR\nSERVICE_NAME=$SERVICE_NAME\nLINKED_FILES=\nLINKED_DIRS=\n" >> deploy/app-config.sh
printf "PROJECT_ENVIRONMENT=$PROJECT_ENVIRONMENT\nGIT_BRANCH=master\nBUILD=''\nFORMAT=nextjs\n" >> deploy/environments/default/config.sh
cat deploy/app-config.sh
cat deploy/environments/default/config.sh
title 'TEST - deploying default environment'
rm -rf $TEST_WORKING_DIR
#sh deploy/deploy.sh default
PROJECT_DEPLOY_DIR=$PROJECT_DEPLOY_DIR sh $SCRIPT_PATH/../scripts/deploy.sh default
cd $TEST_WORKING_DIR/nextjs-deploy-test/default/current
cp $COPY_PROJECT_DIR/$PROJECT_FILES_DIR/package.json.deploy ./package.json
cp $COPY_PROJECT_DIR/$PROJECT_FILES_DIR/tmp-webserver.js ./
cp $COPY_PROJECT_DIR/$PROJECT_FILES_DIR/phantomjs.js ./
# npm init -y
#npm i
npm i connect serve-static phantomjs-prebuilt --save-dev
node tmp-webserver.js $TEST_WORKING_DIR/nextjs-deploy-test/default/current &
# npm run dev-server &
sleep 6
SRV_SCRIPT_PID=$(ps -elf | grep 'tmp-webserver' | grep -v grep | awk '{print $4}')
info "Temp Web Server PID: $SRV_SCRIPT_PID"
title 'TEST - check web application'
export PATH="$TEST_WORKING_DIR/nextjs-deploy-test/default/current/node_modules/phantomjs-prebuilt/lib/phantom/bin:$PATH"
phantomjs phantomjs.js > index.test.html 2>&1
printf 'Checking index page contents ... '
if [ $(grep -c 'Welcome to React Parcel Micro App!' index.test.html) -eq 1 ]; then
success 'success!'
else
error 'fail! :('
fi
kill -9 $SRV_SCRIPT_PID
cd $SCRIPT_PATH/../
rm -rf /tmp/deploy-scripts
15 changes: 15 additions & 0 deletions tests/resources/nextjs-project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "nextjs-project",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "10.2.3",
"react": "17.0.2",
"react-dom": "17.0.2"
}
}
5 changes: 5 additions & 0 deletions tests/resources/nextjs-project/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}

export default MyApp
5 changes: 5 additions & 0 deletions tests/resources/nextjs-project/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function Home() {
return (
<h1>Welcome to Nextjs Parcel Micro App!</h1>
)
}