diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 8786913..665cb1e 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -1,43 +1,74 @@ -# Simple workflow for deploying static content to GitHub Pages -name: Deploy static content to Pages - -on: - # Runs on pushes targeting the default branch - push: - branches: ["main"] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages -permissions: - contents: read - pages: write - id-token: write - -# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. -# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. -concurrency: - group: "pages" - cancel-in-progress: false - +# 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: - # Single deploy job since we're just deploying deploy: - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} + name: "Deploy to server" runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup Pages - uses: actions/configure-pages@v4 - - name: Upload artifact - uses: actions/upload-pages-artifact@v3 - with: - # Upload entire repository - path: '.' - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4 + - 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 <> .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=5" >> .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=uta.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 }}" + \ No newline at end of file diff --git a/src/main/java/com/cse3310/App.java b/src/main/java/com/cse3310/App.java index 20af118..7b40e02 100644 --- a/src/main/java/com/cse3310/App.java +++ b/src/main/java/com/cse3310/App.java @@ -92,17 +92,22 @@ public void onStart() { public static void main(String[] args) { // Set up the http server - String envPort = System.getenv("HTTP_PORT"); - int httpPort = Integer.parseInt(envPort); - HttpServer H = new HttpServer(httpPort, "./html"); - H.start(); - System.out.println("http Server started on port:" + httpPort); - - // create and start the websocket server - envPort = System.getenv("WEBSOCKET_PORT"); - int socketPort = Integer.parseInt("envPort"); - App A = new App(socketPort); - A.start(); - System.out.println("websocket Server started on port: " + socketPort); + try{ + String envPort = System.getenv("HTTP_PORT"); + int httpPort = Integer.parseInt(envPort); + HttpServer H = new HttpServer(httpPort, "./html"); + H.start(); + System.out.println("http Server started on port:" + httpPort); + + // create and start the websocket server + envPort = System.getenv("WEBSOCKET_PORT"); + int socketPort = Integer.parseInt("envPort"); + App A = new App(socketPort); + A.start(); + System.out.println("websocket Server started on port: " + socketPort); + } + catch (NullPointerException e){ // Checks for environment variable + e.printStackTrace(); + } } } diff --git a/target/classes/com/cse3310/App.class b/target/classes/com/cse3310/App.class index 6418857..fa7af53 100644 Binary files a/target/classes/com/cse3310/App.class and b/target/classes/com/cse3310/App.class differ diff --git a/target/classes/com/cse3310/Coordinate.class b/target/classes/com/cse3310/Coordinate.class index f984aef..0c216b8 100644 Binary files a/target/classes/com/cse3310/Coordinate.class and b/target/classes/com/cse3310/Coordinate.class differ diff --git a/target/classes/com/cse3310/Game.class b/target/classes/com/cse3310/Game.class index 4e5b09b..fa96215 100644 Binary files a/target/classes/com/cse3310/Game.class and b/target/classes/com/cse3310/Game.class differ diff --git a/target/classes/com/cse3310/HttpServer$1.class b/target/classes/com/cse3310/HttpServer$1.class index 3218db9..ff5f4de 100644 Binary files a/target/classes/com/cse3310/HttpServer$1.class and b/target/classes/com/cse3310/HttpServer$1.class differ diff --git a/target/classes/com/cse3310/HttpServer.class b/target/classes/com/cse3310/HttpServer.class index 586c59a..2b6716b 100644 Binary files a/target/classes/com/cse3310/HttpServer.class and b/target/classes/com/cse3310/HttpServer.class differ diff --git a/target/classes/com/cse3310/Locations.class b/target/classes/com/cse3310/Locations.class index 21d4d2a..a69f779 100644 Binary files a/target/classes/com/cse3310/Locations.class and b/target/classes/com/cse3310/Locations.class differ diff --git a/target/classes/com/cse3310/ServerEvent.class b/target/classes/com/cse3310/ServerEvent.class index 2ec5abb..c29c1ae 100644 Binary files a/target/classes/com/cse3310/ServerEvent.class and b/target/classes/com/cse3310/ServerEvent.class differ diff --git a/target/classes/com/cse3310/User.class b/target/classes/com/cse3310/User.class index 906400f..d376a46 100644 Binary files a/target/classes/com/cse3310/User.class and b/target/classes/com/cse3310/User.class differ diff --git a/target/classes/com/cse3310/UserEvent.class b/target/classes/com/cse3310/UserEvent.class index 3acce81..2049cc9 100644 Binary files a/target/classes/com/cse3310/UserEvent.class and b/target/classes/com/cse3310/UserEvent.class differ diff --git a/target/test-classes/com/cse3310/AppTest.class b/target/test-classes/com/cse3310/AppTest.class index 50dc4d7..35d0340 100644 Binary files a/target/test-classes/com/cse3310/AppTest.class and b/target/test-classes/com/cse3310/AppTest.class differ