Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial auth key implementation #57

Merged
merged 63 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
9651ef0
Initial auth key implementation
hategan May 26, 2023
124ffa5
Parametrized things a bit
hategan Aug 29, 2023
a6a3930
Root is only really needed for nginx deployment
hategan Aug 29, 2023
c2f5d99
Update deployment scripts to deploy various configuration files,
hategan Aug 29, 2023
036867c
Moved some things out of the service and into config and secrets files.
hategan Aug 29, 2023
e59bed3
Updated version to 0.4.0-testing
hategan Aug 29, 2023
41e6e72
Fixed sample sdk url
hategan Aug 29, 2023
ce37956
TARGET_VERSION is only valid after the command line is processed
hategan Aug 29, 2023
011e21e
Added bcrypt as dependency
hategan Aug 29, 2023
5eb9ddf
... and requests
hategan Aug 29, 2023
74e93c0
Overwrite files on deployment (we may be dealing with installation de…
hategan Aug 29, 2023
89bda86
Use the upgrade script to do post-deploy updates, since that process …
hategan Aug 29, 2023
a03290c
Updated version to 0.4.0-testing2
hategan Aug 29, 2023
0708e94
Ooops
hategan Aug 29, 2023
3f87fd0
Various fixes
hategan Aug 29, 2023
16e5ba4
Docker COPY does not work the way you think it does!
hategan Aug 29, 2023
e5a5697
Updated version to 0.4.0-testing4
hategan Aug 29, 2023
10f4618
Make sure secrets are copied on deployment
hategan Aug 29, 2023
a4cdfef
Small fix
hategan Aug 29, 2023
77fd64d
Allow a fallback admin email to be specified in the config file.
hategan Aug 29, 2023
2c71525
Updated version to 0.4.0-testing5
hategan Aug 29, 2023
38d7828
Copy all possibly customized files on deployment
hategan Aug 29, 2023
4e05d46
Added reCaptchaSiteKey in sdk customization
hategan Aug 29, 2023
e261210
Apparently there's a PEP for versioning and "-testingX" is not approved
hategan Aug 30, 2023
8fd61ec
Also deploy customization files
hategan Aug 30, 2023
b08fbec
Allow frames from google to make recaptcha work
hategan Aug 30, 2023
80501a2
Updated deployment readme
hategan Aug 30, 2023
7533456
pip seems to behave differently on different machines. Sometimes it
hategan Aug 30, 2023
eb3b37c
Fixed typo(s)
hategan Aug 30, 2023
880dc87
Fixed configuration issues
hategan Aug 30, 2023
e48613a
Update deployment customization files. There's a bit of confusion with
hategan Aug 30, 2023
778a605
Updated version to 0.4.0.dev7
hategan Aug 30, 2023
2d33366
Move things to docker/fs rather than copying individual files manually
hategan Aug 30, 2023
c6c9a76
Updated version to 0.4.0.dev8
hategan Aug 30, 2023
60f3c10
Make sure error messages are logged immediately.
hategan Aug 30, 2023
a00752d
Add hostname parameter to container
hategan Aug 30, 2023
907094d
Fixed copy commands
hategan Aug 30, 2023
d4b1806
Postfix work...
hategan Aug 30, 2023
a76df3e
Updated version to 0.4.0.dev9
hategan Aug 30, 2023
885f51b
Some upgrade fixes
hategan Aug 30, 2023
9a78cd2
OOMs can happen if we don't let started services settle a bit
hategan Aug 30, 2023
b7cd0e3
May need a relay, such as AWS SES
hategan Aug 30, 2023
45438c5
Updated version to 0.4.0.dev10
hategan Aug 30, 2023
55a10c1
Fix
hategan Aug 30, 2023
6a17b7a
Moved customized jss
hategan Aug 30, 2023
c12682c
Removed unused parameter
hategan Aug 30, 2023
e4202eb
Fix email variable clash
hategan Aug 30, 2023
95ca625
Updated version to 0.4.0.dev11
hategan Aug 30, 2023
cb260cc
Fix variable name
hategan Aug 30, 2023
26690c4
Fixed template parameter
hategan Aug 31, 2023
906e146
Updated version to 0.4.0.dev12
hategan Aug 31, 2023
e8699ba
We don't really access the sites collection when checking the new key…
hategan Aug 31, 2023
9c11495
Some type annotations and fixes
hategan Aug 31, 2023
1e0bd3d
Updated version to 0.4.0.dev13
hategan Aug 31, 2023
d88b6bf
A few more fixes
hategan Aug 31, 2023
0df1c8d
Updated version to 0.4.0.dev14
hategan Aug 31, 2023
728f896
Site may not exist at this point with new keys
hategan Aug 31, 2023
ed08d14
Updated version to 0.4.0.dev15
hategan Aug 31, 2023
a592373
Fixed wrong parameter name
hategan Aug 31, 2023
27080df
Updated version to 0.4.0.dev16
hategan Aug 31, 2023
01a7d7c
Fixed parameter.
hategan Aug 31, 2023
32ef289
Updated version to 0.4.0.dev17
hategan Aug 31, 2023
6d888c9
Updated version to 0.4.0
hategan Oct 11, 2023
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
2 changes: 1 addition & 1 deletion RELEASE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.3
0.4.0
5 changes: 3 additions & 2 deletions deployment/config
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/bin/bash

GIT_BASE=https://github.com/ExaWorks/psij-testing-service/archive/refs/tags
PACKAGE_NAME=psij-testing-service
GIT_BASE=https://github.com/ExaWorks/$PACKAGE_NAME/archive/refs/tags
VERSION=`cat ../../RELEASE`

# The service version to build the docker container with or use for
# deployment
SERVICE_VERSION=$VERSION

# Docker image to use
IMAGE=hategan/psij-testing-service
IMAGE=hategan/$PACKAGE_NAME

# If DEV is not 0, the deployment script will install the service from
# the parent directory
Expand Down
71 changes: 52 additions & 19 deletions deployment/deploy/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ run() {
echo -n "Running $@..."
echo "> $@" >>deploy.log
OUT=`"$@" 2>&1`
EC=$?
# `
if [ "$?" != "0" ]; then
echo "FAILED"
if [ "$EC" != "0" ]; then
echo "FAILED ($EC)"
echo $OUT
exit 2
fi
Expand All @@ -53,9 +54,22 @@ getId() {
run docker ps -f "name=service-$TYPE" --format "{{.ID}}"
}

waitForContainer() {
ID=$1
echo "Waiting for container $ID..."
while true; do
STATUS=`docker inspect -f '{{.State.Status}}' $ID`
if [ "$STATUS" == "running" ]; then
break
fi
sleep 1
done
}

deployContainer() {
TYPE=$1
PORT=$2
HOST_NAME=$3
getId $TYPE
ID=$OUT
echo "ID: $OUT"
Expand All @@ -71,34 +85,51 @@ deployContainer() {
mkdir -p $DATA_DIR/$TYPE/mongodb
mkdir -p $DATA_DIR/$TYPE/web
cp $ROOT/web/$TYPE/* $DATA_DIR/$TYPE/web

run docker run \
-d -p $PORT:9909 --name "service-$TYPE" \
-d -p $PORT:9909 --name "service-$TYPE" -h $HOST_NAME \
--restart=on-failure:3 \
--volume=$DATA_DIR/$TYPE/mongodb:/var/lib/mongodb \
--volume=$DATA_DIR/$TYPE/web:/var/www/html \
--volume=/etc/letsencrypt:/etc/letsencrypt \
$EXTRA_VOL \
$IMAGE:latest
$IMAGE:$SERVICE_VERSION
UPDATE_CONTAINER=1
fi
if [ "$UPDATE_CONTAINER" != "0" ]; then
getId $TYPE
ID=$OUT
sleep 5
waitForContainer $ID
run docker exec -it $ID bash -c "echo $HOST_NAME > /etc/hostname"

if [ ! -f ../docker/fs/etc/psij-testing-service/secrets.json ]; then
error "No secrets.json found. Please edit/create secrets.json in ../docker/fs/etc/psij-testing-service"
fi
run docker cp ../docker/fs/. $ID:/
run docker exec -it $ID sed -i "s/\$myhostname/$HOST_NAME/g" /etc/postfix/main.cf
run docker exec -it $ID sed -i "s/\$mydomain/$DOMAIN_NAME/g" /etc/postfix/main.cf
run docker exec -it $ID postmap -v hash:/etc/postfix/sasl_passwd
run docker exec -it $ID bash -c "pip show $PACKAGE_NAME | grep 'Location: ' | sed 's/Location: //' | tr -d '\n'"
PACKAGE_LOC=$OUT
run docker cp ../web/. "$ID:$PACKAGE_LOC/psij/web/"
fi
if [ "$UPDATE_CONTAINER" != "0" ]; then
if [ "$DEV" == "1" ]; then
run docker exec -it $ID update-psi-j-testing-service -y $TYPE /psi-j-testing-service-dev
./upgrade.sh -y --force --component $TYPE /psi-j-testing-service-dev
else
run docker exec -it $ID update-psi-j-testing-service -y $TYPE $SERVICE_VERSION
./upgrade.sh -y --force --component $TYPE $SERVICE_VERSION
fi
fi
}

if [ "$USER" != "root" ]; then
error "You need root permissions to run this script."
fi

if service nginx status >/dev/null 2>&1; then
echo "Nginx is already running. Skipping deployment."
UPDATE_NGINX=$FORCED_UPDATE
else
if [ "$USER" != "root" ]; then
error "You need root permissions to run this script."
fi

run apt-get update
run apt-get install -y nginx
UPDATE_NGINX=1
Expand All @@ -111,12 +142,13 @@ filterConf() {
PROXY_REDIRECT="$4"
INTERNAL_PORT="$5"

if [ ! -f "$DST" ]; then
sed -e "s/\${DOMAIN_NAME}/${DOMAIN_NAME}/g" "$SRC" | \
sed -e "s/\${SERVER_NAME}/${SERVER_NAME}/g" | \
sed -e "s/\${PROXY_REDIRECT}/${PROXY_REDIRECT}/g" | \
sed -e "s/\${INTERNAL_PORT}/${INTERNAL_PORT}/g" >"$DST"
if [ -f "$DST" ]; then
cp "$DST" "$DST.bk"
fi
sed -e "s/\${DOMAIN_NAME}/${DOMAIN_NAME}/g" "$SRC" | \
sed -e "s/\${SERVER_NAME}/${SERVER_NAME}/g" | \
sed -e "s/\${PROXY_REDIRECT}/${PROXY_REDIRECT}/g" | \
sed -e "s/\${INTERNAL_PORT}/${INTERNAL_PORT}/g" >"$DST"
}

deploySite() {
Expand All @@ -130,8 +162,9 @@ deploySite() {
ln -f -s "/etc/nginx/sites-available/$NAME" "/etc/nginx/sites-enabled/$NAME"
}

DOMAIN_NAME=`cat DOMAIN_NAME | tr -d '\n'`

if [ "$UPDATE_NGINX" != "0" ]; then
DOMAIN_NAME=`cat DOMAIN_NAME | tr -d '\n'`
filterConf nginx/headers.conf /etc/nginx/snippets/headers.conf
filterConf nginx/nginx.conf /etc/nginx/nginx.conf
filterConf nginx/ssl.conf /etc/nginx/ssl.conf
Expand All @@ -147,5 +180,5 @@ if [ "$UPDATE_NGINX" != "0" ]; then
run service nginx restart
fi

deployContainer psij 9901
deployContainer sdk 9902
deployContainer psij 9901 "psij.$DOMAIN_NAME"
deployContainer sdk 9902 "sdk.$DOMAIN_NAME"
2 changes: 1 addition & 1 deletion deployment/deploy/nginx/headers.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ add_header Referrer-Policy same-origin;
# to switch to fullscreen
add_header Permissions-Policy fullscreen=(self);

add_header Content-Security-Policy "img-src *; frame-src 'none'; media-src 'none'; object-src 'none'; base-uri 'self'; form-action 'self'";
add_header Content-Security-Policy "img-src *; frame-src https://www.google.com; media-src 'none'; object-src 'none'; base-uri 'self'; form-action 'self'";

64 changes: 59 additions & 5 deletions deployment/deploy/upgrade.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,55 @@
#!/bin/bash

set -e

error() {
echo "$@"
exit 1
}

usage() {
echo "Usage:"
echo " upgrade.sh [-h|--help] [-f|--force] [-c | --component] [-y | --assume-yes]"
exit 1
}


FORCE=""
DONTASK=""
COMPONENTS="psij sdk"
DOMAIN_NAME=`cat DOMAIN_NAME | tr -d '\n'`

while [ "$1" != "" ]; do
case "$1" in
-h | --help)
usage
;;
-f | --force)
FORCE="--force"
shift
;;
-y | --assume-yes)
DONTASK="-y"
shift
;;
-c | --component)
COMPONENTS="$2"
shift
shift
;;
*)
TARGET_VERSION=$1
shift
;;
esac
done

if [ ! -f ../config ]; then
error "This script must be run from the deploy directory"
fi

source ../config

TARGET_VERSION=$1


getId() {
TYPE=$1
Expand All @@ -23,11 +60,28 @@ update() {
TYPE=$1
ID=`docker ps -f "name=service-$TYPE" --format "{{.ID}}"`
if [ "$ID" != "" ]; then
docker exec -it $ID update-psi-j-testing-service $TYPE $TARGET_VERSION
# Make sure everything is up to date
docker exec -it $ID apt-get update
docker exec -it $ID apt-get upgrade -y
# Make sure that all files are there if needed
docker cp ../docker/fs/. $ID:/tmp/fs/
docker exec -it $ID bash -c "echo $TYPE.$DOMAIN_NAME > /etc/hostname"
if [ "$DEV" == "1" ]; then
pushd ../..
python setup.py sdist
popd
docker cp ../../dist/$PACKAGE_NAME-$SERVICE_VERSION.tar.gz $ID:/tmp/$PACKAGE_NAME-$SERVICE_VERSION.tar.gz
docker exec -it $ID update-psi-j-testing-service $DONTASK $FORCE --src /tmp/$PACKAGE_NAME-$SERVICE_VERSION.tar.gz $TYPE $TARGET_VERSION
else
# Actual update
docker exec -it $ID update-psi-j-testing-service $DONTASK $FORCE $TYPE $TARGET_VERSION
fi
else
echo "Service $TYPE not running."
fi
}

update psij
update sdk

for COMPONENT in $COMPONENTS; do
update $COMPONENT
done
20 changes: 12 additions & 8 deletions deployment/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
FROM ubuntu:20.04

ARG SERVICE_VERSION
ARG GIT_BASE=https://github.com/ExaWorks/psij-testing-service/archive/refs/tags
ARG SERVICE_PACKAGE

RUN useradd -ms /bin/bash testsrv

RUN apt-get update
RUN apt-get upgrade -y

RUN DEBIAN_FRONTEND="noninteractive" TZ="UTC" apt-get install -y python3.9 python3-pip mongodb wget mc
RUN DEBIAN_FRONTEND="noninteractive" TZ="UTC" apt-get install -y python3.9 python3-pip mongodb \
wget mc postfix procmail syslog-ng

WORKDIR ~/

RUN pip install $GIT_BASE/v$SERVICE_VERSION.tar.gz
# needed to get syslog-ng to work inside the container
RUN sed -i 's/system()/system(exclude-kmsg(yes))/g' /etc/syslog-ng/syslog-ng.conf

COPY psi-j-testing-service /etc/init.d
COPY entrypoint.sh /
COPY update-psi-j-testing-service /usr/bin

COPY $SERVICE_PACKAGE /tmp
RUN pip install /tmp/$SERVICE_PACKAGE
RUN rm /tmp/$SERVICE_PACKAGE

COPY fs /
RUN mkdir /var/log/psi-j-testing-service
RUN chown testsrv:testsrv /var/log/psi-j-testing-service

CMD /entrypoint.sh
CMD /entrypoint.sh
19 changes: 16 additions & 3 deletions deployment/docker/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

error() {
echo "$@"
exit 1
Expand All @@ -13,8 +15,19 @@ source ../config

echo "Version: $VERSION"

if [ "$DEV" == "1" ]; then
pushd ../..
python setup.py sdist
popd
cp ../../dist/$PACKAGE_NAME-$SERVICE_VERSION.tar.gz ./$PACKAGE_NAME-$SERVICE_VERSION.tar.gz
else
wget $GIT_BASE/v$SERVICE_VERSION.tar.gz -O ./$PACKAGE_NAME-$SERVICE_VERSION.tar.gz
fi


docker build --build-arg SERVICE_VERSION=$SERVICE_VERSION --build-arg GIT_BASE="$GIT_BASE" -t $IMAGE:$VERSION .
docker push $IMAGE:$VERSION
docker build --build-arg SERVICE_PACKAGE=./$PACKAGE_NAME-$SERVICE_VERSION.tar.gz -t $IMAGE:$VERSION .
docker image tag $IMAGE:$VERSION $IMAGE:latest
docker push $IMAGE:latest
if [ "$DEV" == "0" ]; then
docker push $IMAGE:$VERSION
docker push $IMAGE:latest
fi
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/bin/bash

set -e

service syslog-ng start
chown -R mongodb:mongodb /var/lib/mongodb
service mongodb start
service postfix start

service psi-j-testing-service start

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ start() {
log_progress_msg "already running"
errorcode=0
else
# without this, errors get delayed in the log
export PYTHONUNBUFFERED=1
start-stop-daemon --background --start --quiet --pidfile $PIDFILE \
--make-pidfile --chuid $DAEMONUSER \
--startas /bin/bash -- -c "exec psi-j-testing-service >>/var/log/psi-j-testing-service/service.log 2>&1"
--startas /bin/bash -- -c "exec psi-j-testing-service -c /etc/psij-testing-service/config.json -s /etc/psij-testing-service/secrets.json >>/var/log/psi-j-testing-service/service.log 2>&1"
errorcode=$?
fi
return $errorcode
Expand Down
Empty file.
Loading