mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
Success to send command to api
+ require sourcing entrypoint.sh manually
This commit is contained in:
1 parent
9f74a80551
commit
9376e16f72
7 files changed
+74
-2
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
containers=$(docker ps -a | grep 'quest-' | awk '{print $1}')
|
||||||
|
echo $containers
|
||||||
|
|
||||||
|
docker rm -f $containers
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
image: lancatlin/linux-odyssey
|
||||||
|
restart: on-failure
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
networks:
|
||||||
|
- internal
|
||||||
|
- players
|
||||||
|
ports:
|
||||||
|
- '3000:3000'
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
environment:
|
||||||
|
- MONGO_URL=mongodb://db:27017/odyssey-test
|
||||||
|
- DOCKER_NETWORK=linux-odyssey-players
|
||||||
|
db:
|
||||||
|
image: mongo
|
||||||
|
restart: always
|
||||||
|
networks:
|
||||||
|
- internal
|
||||||
|
ports:
|
||||||
|
- '27017:27017'
|
||||||
|
volumes:
|
||||||
|
- ./data:/data/db
|
||||||
|
|
||||||
|
networks:
|
||||||
|
internal:
|
||||||
|
players:
|
||||||
|
name: linux-odyssey-players
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
version: '3'
|
version: '3'
|
||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
image: lancatlin/linux-odyssey
|
|
||||||
restart: on-failure
|
restart: on-failure
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
FROM ubuntu:latest
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y \
|
||||||
|
curl \
|
||||||
|
vim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
CMD [ "/bin/bash" ]
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# enable programmable completion features (you don't need to enable
|
||||||
|
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
|
||||||
|
# sources /etc/bash.bashrc).
|
||||||
|
#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
|
||||||
|
# . /etc/bash_completion
|
||||||
|
#fi
|
||||||
|
|
||||||
|
# This function will be called before each command is executed
|
||||||
|
preexec() {
|
||||||
|
[ -n "$COMP_LINE" ] && return # do nothing if completing
|
||||||
|
[ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return # do nothing if completing
|
||||||
|
local command="$BASH_COMMAND"
|
||||||
|
local pwd="$PWD"
|
||||||
|
|
||||||
|
# Store command in variable
|
||||||
|
local cmd=$(printf '{"token": "%s", "pwd": "%s", "command": "%s"}' "$TOKEN" "$pwd" "$command")
|
||||||
|
|
||||||
|
# Send command to the API
|
||||||
|
curl -X POST $API_ENDPOINT/api/v1/commands -H 'accept: */*' -H 'Content-Type: application/json' -d "$cmd"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Install the trap
|
||||||
|
trap 'preexec' DEBUG
|
||||||
@@ -4,6 +4,7 @@ import Session from '../../models/session.js'
|
|||||||
import { verifySessionJWT } from '../../utils/auth.js'
|
import { verifySessionJWT } from '../../utils/auth.js'
|
||||||
|
|
||||||
export async function newCommand(req, res) {
|
export async function newCommand(req, res) {
|
||||||
|
console.log('new command:', req.body)
|
||||||
const { token, command, pwd, output } = req.body
|
const { token, command, pwd, output } = req.body
|
||||||
|
|
||||||
let sessionId
|
let sessionId
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ export default (server) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
socket.on('message', function incoming(message) {
|
socket.on('message', function incoming(message) {
|
||||||
console.log(`From client: ${message}`)
|
|
||||||
stream.write(message)
|
stream.write(message)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user