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
9b50b77e
Commit
9b50b77e
authored
2 years ago
by
Fredrik Fonn Hansen
Browse files
Options
Downloads
Plain Diff
Merge branch 'CI-deploy-to-vm' into 'main'
Ci deploy to vm See merge request
!26
parents
f24afea4
f0f23786
No related branches found
Branches containing commit
No related tags found
1 merge request
!26
Ci deploy to vm
Pipeline
#211228
passed
2 years ago
Stage: backend test
Stage: frontend test
Stage: deploy
Changes
4
Pipelines
1
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 @
9b50b77e
...
@@ -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
:
3
1
ANDROID_COMPILE_SDK
:
3
3
ANDROID_BUILD_TOOLS
:
3
1
.0.0
ANDROID_BUILD_TOOLS
:
3
3
.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"
This diff is collapsed.
Click to expand it.
backend/README.md
+
8
−
0
View file @
9b50b77e
...
@@ -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)
This diff is collapsed.
Click to expand it.
backend/src/index.ts
+
3
−
2
View file @
9b50b77e
...
@@ -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
=
300
0
;
const
port
=
8
0
;
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
'
);
...
...
This diff is collapsed.
Click to expand it.
backend/vm.sh
0 → 100644
+
19
−
0
View file @
9b50b77e
#!/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