Skip to content

Commit

Permalink
Merge pull request #337 from amosproj/deployment-actions
Browse files Browse the repository at this point in the history
Deployment actions
  • Loading branch information
PianoRollRepresentation authored Jun 22, 2021
2 parents ad55ea6 + 0f9a2cf commit 232fab0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
27 changes: 27 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -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" > [email protected]
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


36 changes: 36 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion upload-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 232fab0

Please sign in to comment.