Skip to content
Snippets Groups Projects
Commit 9b50b77e authored by Fredrik Fonn Hansen's avatar Fredrik Fonn Hansen :8ball:
Browse files

Merge branch 'CI-deploy-to-vm' into 'main'

Ci deploy to vm

See merge request !26
parents f24afea4 f0f23786
No related branches found
No related tags found
1 merge request!26Ci deploy to vm
Pipeline #211228 passed
...@@ -3,6 +3,7 @@ stages: ...@@ -3,6 +3,7 @@ stages:
- frontend build - frontend build
- backend test - backend test
- frontend test - frontend test
- deploy
cache: cache:
key: ${CI_COMMIT_REF_SLUG} key: ${CI_COMMIT_REF_SLUG}
...@@ -16,13 +17,13 @@ cache: ...@@ -16,13 +17,13 @@ cache:
variables: variables:
# Specify the SDK tools version and build tools version to use # Specify the SDK tools version and build tools version to use
ANDROID_COMPILE_SDK: 31 ANDROID_COMPILE_SDK: 33
ANDROID_BUILD_TOOLS: 31.0.0 ANDROID_BUILD_TOOLS: 33.0.0
ANDROID_SDK_TOOLS: 7583922 ANDROID_SDK_TOOLS: 7583922
ANDROID_HOME: "/usr/local/android-sdk" ANDROID_HOME: "/usr/local/android-sdk"
Prettier check: Prettier:
image: node:16.3.0 image: node:16.3.0
stage: backend test stage: backend test
needs: [] needs: []
...@@ -32,27 +33,42 @@ Prettier check: ...@@ -32,27 +33,42 @@ Prettier check:
- yarn prettier --check . - yarn prettier --check .
retry: 1 retry: 1
Backend build: Typescript-compile:
image: node:16.3.0 image: node:16.3.0
stage: backend test stage: backend test
needs: [] needs: []
script: script:
- cd backend - cd backend
- yarn - yarn
- yarn tsc - yarn tsc
Frontend build: Gradle-build:
image: gradle:7.5.0-jdk11 image: gradle:7.5.0-jdk11
stage: backend test stage: frontend test
needs: [] needs: []
script: script:
# Restore Android SDK from cache # Restore Android SDK from cache
- if [ -d android-sdk ]; then mv android-sdk/* $ANDROID_HOME/; fi #- if [ -d android-sdk ]; then mv android-sdk/* $ANDROID_HOME/; fi
# Download and install Android SDK # Download and install Android SDK
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip - wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip
- unzip -q android-sdk.zip -d android-sdk - unzip -q -o android-sdk.zip -d android-sdk
- echo y | android-sdk/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME "platforms;android-${ANDROID_COMPILE_SDK}" "build-tools;${ANDROID_BUILD_TOOLS}" - rm -rf $ANDROID_HOME/platforms/android-33
- cd frontend - echo y | android-sdk/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME "platforms;android-${ANDROID_COMPILE_SDK}" "build-tools;${ANDROID_BUILD_TOOLS}"
- ./gradlew clean - cd frontend
- ./gradlew build --refresh-dependencies - ./gradlew clean
- gradle build - ./gradlew build --refresh-dependencies
- gradle build
Backend (NTNU-VM):
image: node:16.3.0
stage: deploy
needs: [Typescript-compile]
before_script:
- mkdir -p ~/.ssh
- echo "$NTNU_VM_SSH_KEY" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- ssh-keyscan 10.212.26.72 >> ~/.ssh/known_hosts
- ssh-keygen -p -f ~/.ssh/id_rsa
script:
- ssh -v -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no ubuntu@10.212.26.72 -p 22 "bash /home/git/tdt4240-tank-wars/backend/vm.sh </dev/null >/dev/null 2>&1"
...@@ -25,3 +25,11 @@ Run the following commands in your terminal: ...@@ -25,3 +25,11 @@ Run the following commands in your terminal:
Formatere koden: `yarn prettier` Formatere koden: `yarn prettier`
Kjøre tester: `yarn test` Kjøre tester: `yarn test`
## VM Deployment
The backend runs on NTNU VM.
IP: 10.212.26.72
Port: 80
`vm.sh` defines the code that is needed to boot the vm (after CI connectes to the VM with SSH)
...@@ -4,7 +4,7 @@ import { User } from '../types/User'; ...@@ -4,7 +4,7 @@ import { User } from '../types/User';
import { GameHandler } from './gameHandler'; import { GameHandler } from './gameHandler';
const app = express(); const app = express();
const port = 3000; const port = 80;
const gameHandler = new GameHandler(); // singleton ;) const gameHandler = new GameHandler(); // singleton ;)
...@@ -22,10 +22,11 @@ app.get('/', (req, res) => { ...@@ -22,10 +22,11 @@ app.get('/', (req, res) => {
res.send('Hello, World!'); res.send('Hello, World!');
}); });
app.listen(port, () => { app.listen(port, '0.0.0.0', () => {
console.log(`Server started on port ${port}`); console.log(`Server started on port ${port}`);
}); });
// establish connection to firebase // establish connection to firebase
const admin = require('firebase-admin'); const admin = require('firebase-admin');
const serviceAccount = path.join(__dirname, '../..', 'keys', 'fb-key.json'); const serviceAccount = path.join(__dirname, '../..', 'keys', 'fb-key.json');
......
#!/bin/bash
# Kill the service running on port 80, if any
sudo kill $(sudo lsof -t -i:80)
# Start the Express.js app
cd /home/git/tdt4240-tank-wars/backend && sudo git pull && sudo npx yarn && sudo npx yarn start >/dev/null 2>&1 &
# Wait for the app to start and check the status
BACKEND_PID=$!
sleep 10
if ps -p $BACKEND_PID > /dev/null; then
echo "Backend started successfully"
exit 0
else
echo "Backend failed to start"
exit 1
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment