Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TDT4240 Tank Wars
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Snorre Skjellestad Kristiansen
TDT4240 Tank Wars
Commits
f0f23786
Commit
f0f23786
authored
2 years ago
by
Fredrik Fonn Hansen
Browse files
Options
Downloads
Patches
Plain Diff
Ci deploy to vm
parent
f24afea4
No related branches found
Branches containing commit
No related tags found
1 merge request
!26
Ci deploy to vm
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitlab-ci.yml
+43
-27
43 additions, 27 deletions
.gitlab-ci.yml
backend/README.md
+8
-0
8 additions, 0 deletions
backend/README.md
backend/src/index.ts
+3
-2
3 additions, 2 deletions
backend/src/index.ts
backend/vm.sh
+19
-0
19 additions, 0 deletions
backend/vm.sh
with
73 additions
and
29 deletions
.gitlab-ci.yml
+
43
−
27
View file @
f0f23786
...
...
@@ -3,6 +3,7 @@ stages:
-
frontend build
-
backend test
-
frontend test
-
deploy
cache
:
key
:
${CI_COMMIT_REF_SLUG}
...
...
@@ -16,13 +17,13 @@ cache:
variables
:
# Specify the SDK tools version and build tools version to use
ANDROID_COMPILE_SDK
:
3
1
ANDROID_BUILD_TOOLS
:
3
1
.0.0
ANDROID_COMPILE_SDK
:
3
3
ANDROID_BUILD_TOOLS
:
3
3
.0.0
ANDROID_SDK_TOOLS
:
7583922
ANDROID_HOME
:
"
/usr/local/android-sdk"
Prettier
check
:
Prettier
:
image
:
node:16.3.0
stage
:
backend test
needs
:
[]
...
...
@@ -32,27 +33,42 @@ Prettier check:
-
yarn prettier --check .
retry
:
1
Backend build
:
image
:
node:16.3.0
stage
:
backend test
needs
:
[]
script
:
-
cd backend
-
yarn
-
yarn tsc
Frontend build
:
image
:
gradle:7.5.0-jdk11
stage
:
backend test
needs
:
[]
script
:
# Restore Android SDK from cache
-
if [ -d android-sdk ]; then mv android-sdk/* $ANDROID_HOME/; fi
# 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
-
unzip -q 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}"
-
cd frontend
-
./gradlew clean
-
./gradlew build --refresh-dependencies
-
gradle build
Typescript-compile
:
image
:
node:16.3.0
stage
:
backend test
needs
:
[]
script
:
-
cd backend
-
yarn
-
yarn tsc
Gradle-build
:
image
:
gradle:7.5.0-jdk11
stage
:
frontend test
needs
:
[]
script
:
# Restore Android SDK from cache
#- if [ -d android-sdk ]; then mv android-sdk/* $ANDROID_HOME/; fi
# 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
-
unzip -q -o android-sdk.zip -d android-sdk
-
rm -rf $ANDROID_HOME/platforms/android-33
-
echo y | android-sdk/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME "platforms;android-${ANDROID_COMPILE_SDK}" "build-tools;${ANDROID_BUILD_TOOLS}"
-
cd frontend
-
./gradlew clean
-
./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"
This diff is collapsed.
Click to expand it.
backend/README.md
+
8
−
0
View file @
f0f23786
...
...
@@ -25,3 +25,11 @@ Run the following commands in your terminal:
Formatere koden:
`yarn prettier`
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)
This diff is collapsed.
Click to expand it.
backend/src/index.ts
+
3
−
2
View file @
f0f23786
...
...
@@ -4,7 +4,7 @@ import { User } from '../types/User';
import
{
GameHandler
}
from
'
./gameHandler
'
;
const
app
=
express
();
const
port
=
300
0
;
const
port
=
8
0
;
const
gameHandler
=
new
GameHandler
();
// singleton ;)
...
...
@@ -22,10 +22,11 @@ app.get('/', (req, res) => {
res
.
send
(
'
Hello, World!
'
);
});
app
.
listen
(
port
,
()
=>
{
app
.
listen
(
port
,
'
0.0.0.0
'
,
()
=>
{
console
.
log
(
`Server started on port
${
port
}
`
);
});
// establish connection to firebase
const
admin
=
require
(
'
firebase-admin
'
);
const
serviceAccount
=
path
.
join
(
__dirname
,
'
../..
'
,
'
keys
'
,
'
fb-key.json
'
);
...
...
This diff is collapsed.
Click to expand it.
backend/vm.sh
0 → 100644
+
19
−
0
View file @
f0f23786
#!/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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment