Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync fork #9537

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/node_modules
**/dist
**/build
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
*.tar.gz*
.idea/

# Mac OS
.DS_Store

# NPM
/node_modules
**/node_modules
npm-*

# Testing
Expand Down
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:18.18.2 as build-stage
RUN npm install -g [email protected]
RUN npm config set strict-ssl false
WORKDIR /app
COPY package*.json ./
ENV NODE_OPTIONS "--openssl-legacy-provider"
RUN npm install --registry=https://registry.npm.taobao.org
COPY ./ .
RUN cp -r scratch-vm/* node_modules/scratch-vm/
RUN cd node_modules/scratch-vm/src/extensions/scratch3_rocketscience && npm install --registry=https://registry.npm.taobao.org
RUN npm run build

FROM nginx as production-stage
RUN mkdir /app
COPY --from=build-stage /app/build /app
COPY nginx.conf /etc/nginx/nginx.conf
18 changes: 18 additions & 0 deletions build_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# MUST run in folder "scratch-gui"

IMAGE=$1

if [ -z "$IMAGE" ]; then
printf "Usage:
build_image.sh [image]
Example:
bash build_image.sh scratch_gui
"
exit 0
fi

echo "Building docker image..."
docker build . -t "$IMAGE" --compress
docker save -o "$IMAGE".tar.gz "$IMAGE"
45 changes: 45 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

# MUST run in folder "scratch-gui"

IMAGE=$1
TARGET=$2
USERNAME=$3
PORT=$4
FLAG=$5
if [ -z "$IMAGE" ] || [ -z "$TARGET" ] || [ -z "$USERNAME" ] || [ -z "$PORT" ]; then
printf "Usage:
deploy.sh image ip user_name port [cp-only]
Example:
bash deploy.sh scratch_gui 192.168.31.222 kxconsole 8601:8601 [cp-only]
"
exit 0
fi

if [ ! -f "$IMAGE.tar.gz" ];
then
echo "Building docker image..."
docker build . -t "$IMAGE" --compress
docker save -o "$IMAGE".tar.gz "$IMAGE"
fi

echo "12345678" | ssh -tt $USERNAME@$TARGET '
[ ! -d /opt/soft/'"$IMAGE"' ] && sudo mkdir -p /opt/soft/'"$IMAGE"' && sudo chown -R '$USERNAME':'$USERNAME' /opt'

echo "scp -p -C ./"$IMAGE".tar.gz $USERNAME@$TARGET:/opt/soft/'"$IMAGE"'"
scp -p -C ./"$IMAGE".tar.gz $USERNAME@$TARGET:/opt/soft/$IMAGE

if [ -n "$FLAG" ] && [ "$FLAG" == "cp-only" ] ; then
echo "Skip restarting ScratchGUI, exit"
exit 0
fi

echo "Starting ScratchGUI..."
echo "12345678" | ssh -tt $USERNAME@$TARGET '
cd /opt/soft/'"$IMAGE"';
sudo docker container stop $(sudo docker container ls -aq -f "ancestor='"$IMAGE"'");
sudo docker load --input '"$IMAGE"'.tar.gz;
sudo docker run -d -p '"$PORT"' '"$IMAGE"';
sudo docker container rm $(sudo docker container ls -aq -f "status=exited");
sudo docker rmi $(sudo docker images -f "dangling=true" -q --no-trunc);
'
31 changes: 31 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 8601;
server_name localhost scratch.kanxing.com;
location / {
root /app;
index index.html;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}

Loading
Loading