Skip to content

Instantly share code, notes, and snippets.

@ziedHamdi
Last active November 16, 2021 13:29
Show Gist options
  • Save ziedHamdi/b593151ec23967fc1b80588ca6bdcadc to your computer and use it in GitHub Desktop.
Save ziedHamdi/b593151ec23967fc1b80588ca6bdcadc to your computer and use it in GitHub Desktop.
#!/bin/bash
# GRAPHQL_SERVER_VERSION=$1
# NEXT_SERVER_VERSION=$2
# set variables from .env to system: https://gist.github.com/mihow/9c7f559807069a03e302605691f85572
if [ -f .env ]
then
export $(cat .env | sed 's/#.*//g' | xargs)
fi
echo Building version $GRAPHQL_SERVER_VERSION of backend and version $NEXT_SERVER_VERSION of frontend
if [ -z $GRAPHQL_SERVER_VERSION ]
then
echo you didn''t specify the tag for the BACKEND git repository
exit
fi
if [ -z $NEXT_SERVER_VERSION ]
then
echo you didn''t specify the tag for the FRONTEND git repository
exit
fi
buildGraphQL="true"
buildNext="true"
buildNginx="true"
# found here: https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
while [[ "$#" -gt 0 ]]; do
case $1 in
-s|--skip) skip="$2";
shift;
if [[ $skip == *"back"* ]]; then
echo "buildGraphQL value: $buildGraphQL"
buildGraphQL="false"
echo "skipping backend weallyback server build"
fi
if [[ $skip == *"front"* ]]; then
buildNext="false"
echo "skipping frontend weally.org server build"
fi
if [[ $skip == *"nginx"* ]]; then
buildNginx="false"
echo "skipping nginx proxy server build"
fi
;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done
cd .. # > prod/
echo "building buildGraphQL: $buildGraphQL, buildNext: $buildNext"
if [ "$buildGraphQL" = "true" ] ; then
sudo rm -rf weallyback
git clone --depth 1 --branch $GRAPHQL_SERVER_VERSION https://1vu@bitbucket.org/1vu/weallyback.git
cd weallyback
# > prod/weallyback/
echo building backend server
cd ../weally_conf
pwd
docker-compose run --rm graphql_server yarn install --production=false
docker-compose run --rm graphql_server yarn build
# docker build . -t graphql:$GRAPHQL_SERVER_VERSION
cd .. # > prod/
fi
if [ "$buildNext" = "true" ] ; then
sudo rm -rf weally.org
git clone --depth 1 --branch $NEXT_SERVER_VERSION https://1vu@bitbucket.org/1vu/weally.org.git
cd weally.org
cp -a -rf --verbose ../weally_conf/front/. .
# > prod/weally.org/
echo building frontend server
cd ../weally_conf
pwd
docker-compose run --rm next_server yarn install --production=false
docker-compose run --rm next_server yarn build
# docker build . -t frontend:$NEXT_SERVER_VERSION
cd .. # > prod/
fi
if [ "$buildNginx" = "true" ] ; then
cd weally_conf
# avoid write denial: https://stackoverflow.com/questions/41286028/docker-build-error-checking-context-cant-stat-c-users-username-appdata
sudo chown -R $USER .
docker build -f nginx.dockerfile -t nginx:0.1 .
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment