Skip to content

Commit

Permalink
basic docker + postgres setup
Browse files Browse the repository at this point in the history
  • Loading branch information
pan261 committed Jan 30, 2022
1 parent a148ac1 commit 9530282
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 59 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Set to ignore everything except /src and package.json
*
!src
!package.json
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ node_modules
credentials.json
download_tests
build
FileShare
file_share
postgres/db_data
66 changes: 17 additions & 49 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: "3.8"

services:

server:
build:
context: .
Expand All @@ -9,55 +10,22 @@ services:
volumes:
- ./src/build:/ffs/
- /ffs/node_modules
- ./FileShare:/ffs/FileShare/
- ./file_share:/ffs/file_share/
- ${LOCAL_DIR_GANTRY}:/ffs/file_share/Gantry/
- ${LOCAL_DIR_MILL}:/ffs/file_share/Mill/
- ${LOCAL_DIR_LATHE}:/ffs/file_share/Lathe/
- ${LOCAL_DIR_WATERJET}:/ffs/file_share/Waterjet/
ports:
- ${PORT}:${PORT}
- ${PORT_SERVER}:${PORT_SERVER}
command: "node server.js"

# task_runner_gantry:
# build:
# context: .
# dockerfile: Dockerfile
# env_file: ./.env
# volumes:
# - ./src/build:/ffs/
# - /ffs/node_modules
# - ${LOCAL_DIR_GANTRY}:/ffs/FileShare/Gantry
# network_mode: host
# command: "node taskRunner.js gantry"
#
# task_runner_lathe:
# build:
# context: .
# dockerfile: Dockerfile
# env_file: ./.env
# volumes:
# - ./src/build:/ffs/
# - /ffs/node_modules
# - ${LOCAL_DIR_LATHE}:/ffs/FileShare/Lathe
# network_mode: host
# command: "node taskRunner.js lathe"

# task_runner_mill:
# build:
# context: .
# dockerfile: Dockerfile
# env_file: ./.env
# volumes:
# - ./src/build:/ffs/
# - /ffs/node_modules
# - ${LOCAL_DIR_MILL}:/ffs/FileShare/Mill
# network_mode: host
# command: "node taskRunner.js mill"

# task_runner_waterjet:
# build:
# context: .
# dockerfile: Dockerfile
# env_file: ./.env
# volumes:
# - ./src/build:/ffs/
# - /ffs/node_modules
# - ${LOCAL_DIR_WATERJET}:/ffs/FileShare/Waterjet
# network_mode: host
# command: "node taskRunner.js waterjet"
# access through `psql -h localhost -p 5432 -d filesync -U user`, password is 'pass'
# to be able to build after the initializing the db, you may need to run `sudo chown -R $USER db_data/`
database:
image: 'postgres:13'
env_file: ./.env
volumes:
- ./postgres/db_data/:/var/lib/postgresql/data/
- ./postgres/sql/create_tables.sql:/docker-entrypoint-initdb.d/create_tables.sql
ports:
- ${PORT_DB}:${PORT_DB}
3 changes: 2 additions & 1 deletion environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ declare global {
FORGE_CLIENT_ID: string;
FORGE_CLIENT_SECRET: string;
FORGE_CALLBACK_URL: string;
PORT: string;
PORT_SERVER: string;
WEBHOOK_TOKEN: string;
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions postgres/sql/create_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CREATE TABLE IF NOT EXISTS fusion (
fusion_id varchar(250) NOT NULL,
file_name varchar(250) NOT NULL,
username varchar(250) NOT NULL,
size int NOT NULL,
version int NOT NULL,
PRIMARY KEY (fusion_id)
);

CREATE TABLE IF NOT EXISTS local (
file_name varchar(250) NOT NULL,
fusion_id varchar(250) NOT NULL,
PRIMARY KEY (file_name)
);

CREATE TABLE IF NOT EXISTS archive (
fusion_id varchar(250) NOT NULL,
file_name varchar(250) NOT NULL,
username varchar(250) NOT NULL,
size int NOT NULL,
version int NOT NULL,
PRIMARY KEY (fusion_id)
);
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ export const folderIDtoLocal: any = {
"urn:adsk.wipprod:fs.folder:co.vJLXAKGbQQayeljr-nwztQ": "/Waterjet"
}

export const port = process.env.PORT;
export const port = process.env.PORT_SERVER;
export const forgeClientId = process.env.FORGE_CLIENT_ID;
export const forgeClientSecret = process.env.FORGE_CLIENT_SECRET;
export const forgeCallbackURL = process.env.FORGE_CALLBACK_URL;
export const hookCallbackURL = `${process.env.HOOK_CALLBACK_HOSTNAME}/hook`;
export const webhookToken: any = process.env.WEBHOOK_TOKEN;
export const webhookToken = process.env.WEBHOOK_TOKEN;
2 changes: 1 addition & 1 deletion src/old/taskRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const projectID = ""

const folderID = config.folderMap[process.argv[2]].fusionID;
const localPath = config.folderMap[process.argv[2]].local;
const localDir = __dirname + '/FileShare' + localPath;
const localDir = __dirname + '/file_share' + localPath;

console.log(folderID, localDir);

Expand Down
6 changes: 3 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const downloader = require('./downloader');
* - FORGE_CLIENT_ID
* - FORGE CLIENT_SECRET
* - FORGE_CALLBACK_URL
* - PORT (defaults to 3000)
* - PORT_SERVER (defaults to 3000)
*
* These are all configured in config.js
*
Expand Down Expand Up @@ -143,7 +143,7 @@ const createServer = () => {
const itemID = body.payload.lineageUrn;
//TODO: check if extension is in the name
const fileName = body.payload.name;
const destination = __dirname + '/FileShare' + config.folderIDtoLocal[body.payload.parentFolderUrn];
const destination = __dirname + '/file_share' + config.folderIDtoLocal[body.payload.parentFolderUrn];

downloader.download(config.projectID, itemID, fileName, destination, credentials);
}
Expand All @@ -155,7 +155,7 @@ const createServer = () => {
res.status(err.statusCode).json(err);
});

const server = app.listen(config.port, () => { console.log(`Server listening on port ${PORT}`); });
const server = app.listen(PORT, () => { console.log(`Server listening on port ${PORT}`); });

return server;
}
Expand Down
4 changes: 2 additions & 2 deletions src/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import * as config from './config';
*
*/

const FileShareID = "urn:adsk.wipprod:fs.folder:co.T0n0mYQeS16K0lq1VuuYVQ"
const fileShareID = "urn:adsk.wipprod:fs.folder:co.T0n0mYQeS16K0lq1VuuYVQ"

/**
* Function to manage hook lifecycle
Expand Down Expand Up @@ -78,7 +78,7 @@ const createHook = (event: string, credentials: any) => {
autoReactivateHook: "true",
callbackUrl: config.hookCallbackURL,
scope: {
folder: FileShareID
folder: fileShareID
}
}
}).then((res: any) => {
Expand Down

0 comments on commit 9530282

Please sign in to comment.