diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..e3a9d1aa --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,27 @@ +name: Deploy +on: + release: + types: [ published ] +jobs: + deploy: + runs-on: ubuntu-latest + strategy: + matrix: + os: [ ubuntu-latest ] + node-version: [ 12.x ] + steps: + - uses: actions/checkout@v2 + - name: Deploy + run: sh ./deploy.sh + - name: Create keyfiles + run: | + echo "$SSH_PRIVATE_KEY" > amos-fau-proj2@group.riehle.org + echo "$SSH_KNOWN_HOSTS" > Server_Keyscan.txt + shell: bash + env: + SSH_PRIVATE_KEY: ${{secrets.CD_SSH_PRIVATE_KEY}} + SSH_KNOWN_HOSTS: ${{secrets.CD_SSH_HOST_KEYS}} + - name: Upload to Server + run: sh ./upload-artifacts.sh + + diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 00000000..7d13d357 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,36 @@ +CopyFilesToFolder () { + fromFolder=$1 + toFolder=$2 + cp -a $fromFolder $toFolder +} + +# Deploy the backend to a docker container +# First copy the shared files, as this is not done during the build process when running in docker +cp -a ./shared/src/. ./backend/src/shared/ + +# Now build the container as spec'ed by the backend dockerfile +docker build -t kmap.backend ./backend + +# Deploy the frontend to a docker container that runs nginx +# First copy the shared files, as this is not done during the build process when running in docker +cp -a ./shared/src/. ./frontend/src/shared/ + +# Remove the .env file, if it is present. +if test -f ./frontend/.env; then + rm ./frontend/.env +fi + +# Now build the container as spec'ed by the backend dockerfile +docker build -t kmap.frontend ./frontend + +# Compose the output folder +if test -d ./artifacts/; then + rm -rf ./artifacts/ +fi + +CopyFilesToFolder ./deploy/ ./artifacts/ +CopyFilesToFolder ./database/ ./artifacts/database/ + +mkdir ./artifacts/images +docker save -o ./artifacts/images/kmap.backend kmap.backend +docker save -o ./artifacts/images/kmap.frontend kmap.frontend diff --git a/upload-artifacts.sh b/upload-artifacts.sh index 8a944d78..193d9fc8 100644 --- a/upload-artifacts.sh +++ b/upload-artifacts.sh @@ -20,5 +20,5 @@ touch $SSH_KNOWN_HOSTS_PATH cat $HOST_PUB_KEY_FILE >> $SSH_KNOWN_HOSTS_PATH ssh -i $SSH_KEY_PATH $USER@$HOST 'cd ~/amos/ && docker-compose down && cd ~ && rm -rf amos' scp -i $SSH_KEY_PATH -r $ARTIFACTS_DIR $USER@$HOST:~/amos/ -ssh -i $SSH_KEY_PATH $USER@$HOST 'cd ~/amos/ && ./kmap.sh' +ssh -i $SSH_KEY_PATH $USER@$HOST 'cd ~/amos/ && sudo chmod +x ./kmap.sh && ./kmap.sh' # read x