Skip to content

Merge pull request #54 from utastudents/w_lobby #207

Merge pull request #54 from utastudents/w_lobby

Merge pull request #54 from utastudents/w_lobby #207

Workflow file for this run

# Derived from an example provided by https://blog.benoitblanchon.fr/github-action-run-ssh-commands/
# https://github.blog/2015-06-16-read-only-deploy-keys/
#
#
#
#
#
name: Deploy
on: [push]
jobs:
deploy:
name: "Deploy to server"
runs-on: ubuntu-latest
steps:
- name: configure SSH
run: |
# These are very useful for debugging
echo "Repository = ${{ github.repository }}"
echo "github url = ${{ github.server_url }}"
echo "Owner = ${{ github.repository_owner }}"
echo "Repository name = ${{ github.event.repository.name }}"
echo "Service name = ${{ vars.SERVICE_NAME }}"
echo "http port = ${{ vars.HTTP_PORT }}"
echo "websocket port = ${{ vars.WEBSOCKET_PORT }}"
echo "version = ${{ github.sha }}"
# On to the work at hand.
mkdir -p ~/.ssh/
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/production.key
chmod 600 ~/.ssh/production.key
cat >>~/.ssh/config <<END
Host production
HostName ${{ secrets.SSH_HOST }}
User ${{ secrets.SSH_USER }}
IdentityFile ~/.ssh/production.key
StrictHostKeyChecking no
END
- name: get source code and compile
run: |
echo "deleting the directory ${{ github.event.repository.name }} "
ssh production "rm -rf ${{ github.event.repository.name }}"
echo "cloning ${{ github.server_url }}/${{ github.repository }}"
ssh production "git clone ${{ github.server_url }}/${{ github.repository }}"
ssh production "cd ${{ github.event.repository.name }}; mvn clean compile package"
- name: create systemd unit file
run: |
# without enable-linger, you must be logged in. So, we enable it.
ssh production "loginctl enable-linger"
ssh production "mkdir --parents .config/systemd/user"
ssh production "rm -f .config/systemd/user/${{ vars.SERVICE_NAME }}.service"
ssh production 'echo "[Unit]" >> .config/systemd/user/${{ vars.SERVICE_NAME }}.service'
ssh production 'echo "Description=${{ vars.SERVICE_NAME }}" >> .config/systemd/user/${{ vars.SERVICE_NAME }}.service'
ssh production 'echo "[Service]" >> .config/systemd/user/${{ vars.SERVICE_NAME }}.service'
ssh production 'echo "Type=simple" >> .config/systemd/user/${{ vars.SERVICE_NAME }}.service'
ssh production 'echo "Restart=always" >> .config/systemd/user/${{ vars.SERVICE_NAME }}.service'
ssh production 'echo "RestartSec=216000" >> .config/systemd/user/${{ vars.SERVICE_NAME }}.service'
ssh production 'echo "Environment=VERSION=\"${{ github.sha }}\"" >>.config/systemd/user/${{ vars.SERVICE_NAME }}.service'
ssh production 'echo "Environment=WEBSOCKET_PORT=${{ vars.WEBSOCKET_PORT }}" >>.config/systemd/user/${{ vars.SERVICE_NAME }}.service'
ssh production 'echo "Environment=HTTP_PORT=${{ vars.HTTP_PORT }}" >>.config/systemd/user/${{ vars.SERVICE_NAME }}.service'
ssh production 'echo "ExecStart=mvn exec:java -Dexec.mainClass=com.cse3310.App" >> .config/systemd/user/${{ vars.SERVICE_NAME }}.service'
ssh production 'echo "WorkingDirectory=$PWD/${{ github.event.repository.name }}" >> .config/systemd/user/${{ vars.SERVICE_NAME }}.service'
ssh production 'echo "[Install]" >>.config/systemd/user/${{ vars.SERVICE_NAME }}.service'
ssh production 'echo "WantedBy=default.target" >>.config/systemd/user/${{ vars.SERVICE_NAME }}.service'
- name: systemd reload
run: |
ssh production "systemctl --user daemon-reload"
- name: restart daemon
run: |
ssh production "systemctl --user enable ${{ vars.SERVICE_NAME }}"
ssh production "systemctl --user restart ${{ vars.SERVICE_NAME }}"
ssh production "systemctl --user status ${{ vars.SERVICE_NAME }}"