R-Nozawa commited on
Commit
345bb79
·
verified ·
1 Parent(s): 01974f1

Upload 2 files

Browse files
Files changed (2) hide show
  1. Dockerfile +10 -4
  2. install_and_run.js +50 -0
Dockerfile CHANGED
@@ -1,11 +1,17 @@
1
- FROM node:20
2
 
3
  WORKDIR /app
4
- COPY . .
5
 
 
 
 
6
  RUN npm install
7
 
8
- ENV PORT=7860
 
 
 
 
9
  EXPOSE 7860
10
 
11
- CMD ["npm", "start"]
 
1
+ FROM node:18
2
 
3
  WORKDIR /app
 
4
 
5
+ RUN apt-get update && apt-get install -y wget unzip
6
+
7
+ COPY package.json .
8
  RUN npm install
9
 
10
+ COPY . .
11
+ COPY install_and_run.js .
12
+
13
+ RUN chown -R node:node /app
14
+
15
  EXPOSE 7860
16
 
17
+ CMD ["node", "install_and_run.js"]
install_and_run.js ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const { exec } = require('child_process');
2
+ const fs = require('fs').promises;
3
+ const path = require('path');
4
+
5
+ const zipUrl = process.env.ZIP_URL;
6
+ const downloadPath = '/tmp/app.zip';
7
+ const extractPath = '/app';
8
+
9
+ async function runCommand(command) {
10
+ return new Promise((resolve, reject) => {
11
+ exec(command, (error, stdout, stderr) => {
12
+ if (error) {
13
+ console.error(`Error executing command: ${command}`);
14
+ console.error(stderr);
15
+ reject(error);
16
+ return;
17
+ }
18
+ console.log(`Command executed successfully: ${command}`);
19
+ console.log(stdout);
20
+ resolve(stdout);
21
+ });
22
+ });
23
+ }
24
+
25
+ async function main() {
26
+ if (!zipUrl) {
27
+ console.error("Error: ZIP_URL environment variable not set.");
28
+ process.exit(1);
29
+ }
30
+
31
+ try {
32
+ console.log(`Downloading ZIP file from: ${zipUrl} to ${downloadPath}`);
33
+ await runCommand(`wget "${zipUrl}" -O ${downloadPath}`);
34
+
35
+ console.log(`Extracting ZIP file to: ${extractPath}`);
36
+ await runCommand(`unzip -o ${downloadPath} -d ${extractPath}`);
37
+
38
+ console.log("Removing downloaded ZIP file...");
39
+ await fs.unlink(downloadPath);
40
+
41
+ console.log("Starting the application...");
42
+ await runCommand('npm start');
43
+
44
+ } catch (error) {
45
+ console.error("An error occurred:", error);
46
+ process.exit(1);
47
+ }
48
+ }
49
+
50
+ main();