From 37a354bdc740bfcc8f131c03f3995883777a3091 Mon Sep 17 00:00:00 2001 From: d0cplay Date: Mon, 23 Aug 2021 13:26:47 +0200 Subject: [PATCH 1/4] added dockerfile --- Dockerfile | 32 ++++++++++++++++++++++++ backend/Config/index.js | 12 ++++----- entrypoint.sh | 6 +++++ frontend/squad-control-panel/src/main.js | 2 +- 4 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 Dockerfile create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8be87fe --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM node:14 + +ENV baseURL "http://localhost/api/v1" +ENV RCON_HOST "" +ENV RCON_PASSWORD "" +ENV RCON_PORT 21114 +ENV JWT_SECRET "" +ENV DB_HOST "" +ENV DB_USER "" +ENV DB_PASS "" +ENV DB_BASE "" +ENV DB_DIAL "" +ENV DB_PORT "" + +RUN yarn global add @vue/cli +WORKDIR /usr/src/sqcp +COPY backend ./backend +COPY frontend/squad-control-panel ./frontend +COPY entrypoint.sh ./entrypoint.sh + +WORKDIR /usr/src/sqcp/frontend +RUN yarn install +RUN yarn build +RUN cp -R ./dist ../backend/ + +WORKDIR /usr/src/sqcp/backend +RUN yarn install + +RUN npm run create-admin + +ENTRYPOINT ["/bin/bash", "/usr/src/sqcp/entrypoint.sh"] +CMD [ "yarn", "start" ] \ No newline at end of file diff --git a/backend/Config/index.js b/backend/Config/index.js index 97e0b18..7f285a2 100644 --- a/backend/Config/index.js +++ b/backend/Config/index.js @@ -12,12 +12,12 @@ const Config = { }, DATABASE: { - host: Database[MODE].host, - user: Database[MODE].username, - password: Database[MODE].password, - database: Database[MODE].database, - dialect: Database[MODE].dialect, - port: Database[MODE].port, + host: process.env.DB_HOST, + user: process.env.DB_USER, + password: process.env.DB_PASS, + database: process.env.DB_BASE, + dialect: process.env.DB_DIAL, + port: process.env.DB_PORT, }, LOGGER_MODULES: { diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..0675bed --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,6 @@ +#entrypoint.sh + +cd ./backend +sequelize db:migrate --config Config/database.json +npm run create-admin +yarn start \ No newline at end of file diff --git a/frontend/squad-control-panel/src/main.js b/frontend/squad-control-panel/src/main.js index 8a18653..a7eb0d2 100644 --- a/frontend/squad-control-panel/src/main.js +++ b/frontend/squad-control-panel/src/main.js @@ -14,7 +14,7 @@ import 'sweetalert2/dist/sweetalert2.min.css'; // Config Vue.config.productionTip = false; -Vue.config.baseURL = 'http://localhost/api/v1'; // Example: http://squad-control-panel.com/api/v1'; +Vue.config.baseURL = process.env.baseURL; // Example: http://squad-control-panel.com/api/v1'; // Plugins Vue.use(VueAxios, axios); From 1f1e6b2c3dd2245b2d360954c03fbbe168bc7886 Mon Sep 17 00:00:00 2001 From: d0cplay Date: Mon, 23 Aug 2021 15:52:22 +0200 Subject: [PATCH 2/4] Added Setup instructions for docker --- docs/setup.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/docs/setup.md b/docs/setup.md index a294714..dd2df0e 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -86,3 +86,52 @@ _PS: I expect you have a technical background and you already are familiar with 21. Restart the server Congratulations, you are done! + +## **Setup via Docker** +1. Create a docker-compose.yml +
Example: + ```yaml + version: '3.1' + + volumes: + sqcp_data: + db_data: + services: + sqcp: + image: sqcp + restart: always + volumes: + - sqcp_data:/usr/src/sqcp/backend/Config/ + ports: + - 3000:3000 + links: + - "db" + environment: + RCON_HOST: "ip" + RCON_PASSWORD: "pw" + RCON_PORT: "21114" + JWT_SECRET: "" + DB_HOST: db + DB_USER: "sqcp" + DB_PASS: "securepw" + DB_BASE: "sqcp" + DB_DIAL: "mysql" + DB_PORT: "3306" + + db: + image: mysql + restart: always + volumes: + - db_data:/var/lib/mysql/ + environment: + MYSQL_ROOT_PASSWORD: "rootpass" + MYSQL_DATABASE: "sqcp" + MYSQL_USER: "sqcp" + MYSQL_PASSWORD: "securepw" + ``` +1. docker-compose up +2. navigate to `/usr/src/sqcp/backend/Config` and add the Database information to `database.json` +3. restart the sqcp container + +Congratulations, you are done! + From 918b26f213b7c5b7595f7718ac1dc554df067e52 Mon Sep 17 00:00:00 2001 From: d0cplay Date: Mon, 23 Aug 2021 15:52:38 +0200 Subject: [PATCH 3/4] minor fixes --- .dockerignore | 23 ++++++++++++++ .gitignore | 27 +++------------- Dockerfile | 6 ++-- docker-compose.yml | 40 ++++++++++++++++++++++++ entrypoint.sh | 4 +-- frontend/squad-control-panel/src/main.js | 2 +- 6 files changed, 74 insertions(+), 28 deletions(-) create mode 100644 .dockerignore create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3937fe6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,23 @@ +.DS_Store +node_modules +/dist + +.gitignore +# local env files +.env.local +.env.*.local + +# Log files +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* + +# Editor directories and files +.idea +.vscode +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/.gitignore b/.gitignore index 403adbc..6ca8164 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,6 @@ -.DS_Store -node_modules -/dist - - -# local env files -.env.local -.env.*.local - -# Log files -npm-debug.log* -yarn-debug.log* -yarn-error.log* -pnpm-debug.log* - -# Editor directories and files +.git +.gitignore .idea -.vscode -*.suo -*.ntvs* -*.njsproj -*.sln -*.sw? +**/node_modules +.DS_Store +.data \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 8be87fe..b02dd90 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM node:14 -ENV baseURL "http://localhost/api/v1" +ENV baseURL "http://localhost:3000/api/v1/" ENV RCON_HOST "" ENV RCON_PASSWORD "" ENV RCON_PORT 21114 @@ -12,6 +12,8 @@ ENV DB_BASE "" ENV DB_DIAL "" ENV DB_PORT "" +EXPOSE 3000 + RUN yarn global add @vue/cli WORKDIR /usr/src/sqcp COPY backend ./backend @@ -26,7 +28,5 @@ RUN cp -R ./dist ../backend/ WORKDIR /usr/src/sqcp/backend RUN yarn install -RUN npm run create-admin - ENTRYPOINT ["/bin/bash", "/usr/src/sqcp/entrypoint.sh"] CMD [ "yarn", "start" ] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f2ee8b6 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,40 @@ +version: '3.1' + +volumes: + sqcp_data: + db_data: +services: + sqcp: + image: sqcp + restart: always + volumes: + - sqcp_data:/usr/src/sqcp/backend/Config/ + ports: + - 3000:3000 + links: + - "db" + environment: + RCON_HOST: "ip" + RCON_PASSWORD: "pw" + RCON_PORT: "21114" + JWT_SECRET: "" + DB_HOST: db + DB_USER: "sqcp" + DB_PASS: "securepw" + DB_BASE: "sqcp" + DB_DIAL: "mysql" + DB_PORT: "3306" + + db: + image: mysql + restart: always + volumes: + - db_data:/var/lib/mysql/ + environment: + MYSQL_ROOT_PASSWORD: "rootpass" + MYSQL_DATABASE: "sqcp" + MYSQL_USER: "sqcp" + MYSQL_PASSWORD: "securepw" + + + \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index 0675bed..b6ed15b 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,6 @@ #entrypoint.sh -cd ./backend -sequelize db:migrate --config Config/database.json +cd /usr/src/sqcp/backend +npx sequelize db:migrate --config Config/database.json npm run create-admin yarn start \ No newline at end of file diff --git a/frontend/squad-control-panel/src/main.js b/frontend/squad-control-panel/src/main.js index a7eb0d2..211df52 100644 --- a/frontend/squad-control-panel/src/main.js +++ b/frontend/squad-control-panel/src/main.js @@ -14,7 +14,7 @@ import 'sweetalert2/dist/sweetalert2.min.css'; // Config Vue.config.productionTip = false; -Vue.config.baseURL = process.env.baseURL; // Example: http://squad-control-panel.com/api/v1'; +Vue.config.baseURL = process.env.baseURL || "http://127.0.0.1:3000/api/v1"; // Example: http://squad-control-panel.com/api/v1'; // Plugins Vue.use(VueAxios, axios); From 2949d1c8118ee82414b42c63965db3b360b08ff7 Mon Sep 17 00:00:00 2001 From: d0cplay Date: Mon, 23 Aug 2021 15:53:23 +0200 Subject: [PATCH 4/4] fixed image link --- docker-compose.yml | 2 +- docs/setup.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index f2ee8b6..7fe010d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ volumes: db_data: services: sqcp: - image: sqcp + image: immervoll/sqcp restart: always volumes: - sqcp_data:/usr/src/sqcp/backend/Config/ diff --git a/docs/setup.md b/docs/setup.md index dd2df0e..bdb67cd 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -98,7 +98,7 @@ Congratulations, you are done! db_data: services: sqcp: - image: sqcp + image: immervoll/sqcp restart: always volumes: - sqcp_data:/usr/src/sqcp/backend/Config/