Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
do
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
do
Commits
0611a9fc
Commit
0611a9fc
authored
Jul 26, 2025
by
Ahmad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dsdsd
parent
6e71ccf2
Pipeline
#235
canceled with stages
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
18 deletions
+19
-18
a.js
a.js
+19
-18
No files found.
a.js
View file @
0611a9fc
...
...
@@ -3,40 +3,41 @@ const path = require('path');
const
os
=
require
(
'
os
'
);
const
axios
=
require
(
'
axios
'
);
//
Read DO token from file
//
Step 1: Read DigitalOcean Token
function
readDigitalOceanToken
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
downloadsDir
=
path
.
join
(
os
.
homedir
(),
'
Downloads
'
);
const
tokenFilePath
=
path
.
join
(
downloadsDir
,
'
do_api_token.txt
'
);
if
(
!
fs
.
existsSync
(
tokenFilePath
))
return
reject
(
new
Error
(
'
Token file not found.
'
));
if
(
!
fs
.
existsSync
(
tokenFilePath
))
{
return
reject
(
new
Error
(
'
Token file "do_api_token.txt" not found in Downloads folder.
'
));
}
fs
.
readFile
(
tokenFilePath
,
'
utf8
'
,
(
err
,
data
)
=>
{
if
(
err
)
return
reject
(
new
Error
(
'
Failed to read token file.
'
));
if
(
err
)
return
reject
(
new
Error
(
`Failed to read token file:
${
err
.
message
}
`
));
const
token
=
data
.
trim
();
const
tokenRegex
=
/^dop_v1_
[
a-z0-9
]{64}
$/i
;
if
(
!
token
)
return
reject
(
new
Error
(
'
Token is empty.
'
));
if
(
!
token
)
return
reject
(
new
Error
(
'
Token
file
is empty.
'
));
if
(
!
tokenRegex
.
test
(
token
))
return
reject
(
new
Error
(
'
Invalid token format.
'
));
resolve
(
token
);
});
});
}
//
Generate random name like maskfjz
//
Step 2: Generate a random server name
function
generateRandomName
()
{
const
rand
=
[...
Array
(
5
)].
map
(()
=>
String
.
fromCharCode
(
97
+
Math
.
floor
(
Math
.
random
()
*
26
))
)
.
join
(
''
);
return
`mas
${
rand
}
`
;
const
rand
omLetters
=
[...
Array
(
5
)]
.
map
(()
=>
String
.
fromCharCode
(
97
+
Math
.
floor
(
Math
.
random
()
*
26
)
))
.
join
(
''
);
return
`mas
${
rand
omLetters
}
`
;
}
//
Prepare user_data
//
Step 3: Prepare user data (Docker + container)
function
getUserData
()
{
return
`#cloud-config
runcmd:
- curl -fsSL https://get.docker.com | sh
- sudo docker run --name node --restart=always -p 3000:3000 -d nematiprog/azzzlll`
;
return
`#cloud-config\nruncmd:\n - curl -fsSL https://get.docker.com | sh\n - sudo docker run --name node --restart=always -p 3000:3000 -d nematiprog/azzzlll`
;
}
//
Check if a "mas*" droplet
already exists
//
Step 4: Check if a droplet with "mas" prefix
already exists
async
function
findMasDroplet
(
token
)
{
const
res
=
await
axios
.
get
(
'
https://api.digitalocean.com/v2/droplets
'
,
{
headers
:
{
Authorization
:
`Bearer
${
token
}
`
}
...
...
@@ -45,7 +46,7 @@ async function findMasDroplet(token) {
return
droplets
.
find
(
d
=>
d
.
name
&&
d
.
name
.
startsWith
(
'
mas
'
))
||
null
;
}
//
Create new droplet if needed
//
Step 5: Create a new droplet
async
function
createDroplet
(
token
,
name
,
userData
)
{
const
payload
=
{
name
,
...
...
@@ -80,7 +81,7 @@ async function createDroplet(token, name, userData) {
}
}
//
Wait until droplet has a public
IPv4
//
Step 6: Wait until droplet gets
IPv4
async
function
waitForIPv4
(
token
,
dropletId
)
{
console
.
log
(
'
⏳ Waiting for droplet to get public IPv4...
'
);
while
(
true
)
{
...
...
@@ -104,7 +105,7 @@ async function waitForIPv4(token, dropletId) {
}
}
// Main
execution
// Main
async
function
main
()
{
try
{
const
token
=
await
readDigitalOceanToken
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment