Skip to content
Snippets Groups Projects
Commit 3a0480d7 authored by Cellar Admin's avatar Cellar Admin 💬
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
{
"presets": [
["@babel/preset-env"]
]
}
\ No newline at end of file
DATABASE_URI=postgres://postgres:postgres@localhost:5432/parse
NODE_ENV=dev
IS_DEVELOPMENT=true
{
"extends": "eslint:recommended",
"env": {
"node": true,
"es2021": true
},
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"parser": "@babel/eslint-parser",
"rules": {
"indent": ["error", 2, { "SwitchCase": 1 }],
"linebreak-style": 0,
"no-trailing-spaces": 2,
"eol-last": 2,
"space-in-parens": ["error", "never"],
"no-multiple-empty-lines": 1,
"prefer-const": "error",
"space-infix-ops": "error",
"no-useless-escape": "off",
"require-atomic-updates": "off",
"no-var": 1,
"no-await-in-loop" : 1
},
"globals" : {
"Parse" : true
}
}
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
.nyc_output
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
dist/
# Dependency directories
node_modules/
jspm_packages/
package-lock.json
yarn.lock
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
# VSCode
.vscode
.vscode-test
# macos system file
.DS_Store
FROM gitpod/workspace-postgres
USER root
RUN mkdir -p /var/lib/pgadmin && \
mkdir -p /var/log/pgadmin && \
chown gitpod /var/lib/pgadmin && \
chown gitpod /var/log/pgadmin
RUN apt-get update && \
apt-get install -y libgtk-3-0 libx11-xcb1 libnss3 libxss1 libasound2 build-essential libssl-dev libffi-dev libgmp3-dev python3-virtualenv libpq-dev python3-dev netcat && \
apt-get clean
RUN pip install pgadmin4
USER gitpod
image:
file: .gitpod.Dockerfile
tasks:
- before: sh ./pgadmin4/setup-web-unattended.sh
init: npm install
command: >
psql --command "CREATE USER postgres WITH SUPERUSER PASSWORD 'postgres';" &&
psql --command "CREATE DATABASE parse;" &&
cp .env.example .env &&
npm run dev
ports:
- port: 1337
onOpen: open-browser
- port: 5050
onOpen: open-browser
- port: 5432
onOpen: ignore
.nycrc 0 → 100644
{
"reporter": [
"lcov",
"text-summary"
],
"exclude": [
"**/spec/**"
]
}
README.md 0 → 100644
# Welcome to the private repo of your Cloud Code!
> This Cloud Code supports Node.js LTS version, nodemon, Jasmine, ESLint & ES6 modules.
Please read our blog about writing better Cloud Code - https://docs.thebrewery.app/blog/2021/05/20/better-cloud-code
# What is Cloud Code?
For complex apps, sometimes you just need a bit of logic that isn’t running on web browser or mobile device. Cloud Code makes this possible.
Cloud Code is easy to use because it’s built on the same Parse JavaScript SDK that powers thousands of apps. The only difference is that this code runs in your Parse Server rather than running on the user’s mobile device or web browser. When you update your Cloud Code, it becomes available to all web and mobile environments instantly. You don’t have to wait for a new release of your application. This lets you change app behavior on the fly and add new features faster.
<br/>
# Let's start brewing!
### 1. Node Version
We highly recommend the LTS version (Node.js 12 or higher).
### 2. Cloud Code development
#### 2.1. For Parse-based code
All your Parse-based code must reside inside `./cloud` folder.
`./cloud/main.js` is the root file which we import on Craft's cloud. **Don't change the name of the cloud directory nor move it**, or else your Cloud Code will not run properly.
For Parse Cloud Code reference and guide:
- https://docs.parseplatform.org/cloudcode/guide/
#### 2.2. For Express-based code
All your Express-based code must reside inside `./express` folder.
> Remember that Express-based code does not have API authentication/authorization support. You need to implement your own authentication/authorization to make your Express-based API secure.
### 3. Hosting your website (optional)
`public/` is the directory in which you can put your `html`, `css`, `js`, `images` files, in case you want to host your app website on Craft for example :)
For example, you can add your static React app's bundle/build on it.
### 4. Deploying your code
When you `git push` changes to the `master` branch of this repo, Craft automatically deploys the code to the servers that your app is working on.
> Remember every push to the `master` branch triggers a deploy. If you want to push you changes without triggering of a deploy, you can push them to another branch, for example `development` branch and when you are done with all the changes ... just merge it with the `master` branch.
<br/><br/>
# Test Craft Cloud Code locally on your computer
So, you have created your first Craft app that comes with built in cloud code functionality and are now wondering what would be the best way to test it. Of course, one of the obvious solutions would be to do a `git push` every time, then test it through the API Console, another REST or GraphQL client, or your app directly. However, you and I both know that there has to be a better way, right?
## Run a local instance of Cloud Code
Running a local instance of the Parse Server with your Cloud Code is the first step you should take as it will allow you to iterate on your app much faster and consequently allow us to debug it. Here's how:
### 1. Clone the source of your app
You can go to your Gitlab profile and find the repo of your app. It will be in `craft-okd4 > [your project group] > [your app name] > cloud-code-app-name`
After you have the repo URL, go to your terminal and run `git clone <url>`.
### 2. Install the npm modules of your app
This will require you to have **node.js** and **npm** installed on your system. We recommend **node.js v12.x** or the latest LTS version.
### 3. Open the directory in your favorite Editor/IDE
In this article, we will use Visual Studio Code.
#### 3.1. Configure your local Parse Server
Set your development environment by copying **_.env.example_** into **_.env_** and adjust the necessary variables. Normally, you will only need to change the DATABASE_URI.
Make necessary adjusments to your `parse-config.js` if needed. Keep in mind that this configuration will **only** affect your local Parse Server. It will look something like this:
```javascript
module.exports = {
databaseURI:
process.env.DATABASE_URI || "postgres://user:pass@localhost:5432/dbname",
appId: process.env.APP_ID || "myAppId",
clientKey: process.env.CLIENT_KEY || "myClientKey",
masterKey: process.env.MASTER_KEY || "masterKey", //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || "http://localhost:1337/parse",
javascriptKey: process.env.JAVASCRIPT_KEY || "myJSKey",
restAPIKey: process.env.REST_API_KEY || "restAPIKey",
cloud: process.env.PARSE_CLOUD_CODE || "./cloud/main.js",
liveQuery: {
classNames: [], // List of classes to support for query subscriptions example: [ 'Posts', 'Comments' ]
},
verbose: false,
};
```
Here, you can change things like your **Application Id** and **Master Key**. You will be running this Parse instance only locally, but it's still a good practice to change your **Master Key**.
It's also recommended to run a local instance of MongoDB or PostgreSQL, **we recommend to use PostgreSQL.**
In case you want to use the same data as your Craft app, you can simply import it in your local PostgreSQL.
We are using [Adminer](https://www.adminer.org/), a DB management tool and we have a great tutorial on that - [Managing Database Using Adminer](https://serverpilot.io/docs/how-to-manage-your-database-with-adminer/).
If you want to export/import data from your Craft app, you can use your Adminer credentials from your Craft app **Settings** page.
#### 3.2. Run it
After you have set it all up, it's time to run your Cloud Code:
`npm run dev`
#### 3.3. Check it
Check that everything is working as expected by running:
`curl localhost:1337/parse/health`
<br/><br/>
By the way, this is the code for connecting a JavaScript SDK instance to your local server looks like, in case you would want to test some queries or test your mobile app or frontend app.
```javascript
Parse.initialize("YOUR_APP_ID", "YOUR_JAVASCRIPT_KEY");
Parse.serverURL = "http://localhost:1337/parse/";
```
⚠️ Please note that the **_master key_** should only be used in safe environments and **_never_** on client side.
For more info on how to use Javascript SDK on client side, pls visit the official [Parse Javascript Guide](https://docs.parseplatform.org/js/guide/)
#### 3.4 Sample Cloud Code Function Query (via cURL)
For Parse-based functions:
Query `parse/functions/<function-name>` via POST
```bash
$ curl -X POST \
-H "X-Parse-Application-Id: your-app-id" \
-H "X-Parse-Master-Key: your-master-key" \
http://localhost:1337/parse/functions/hello
{"result":"Hello! and welcome to Cloud Code (Parse) Functions --from Craft Team"}%
```
For Express-based functions:
```bash
$ curl http://localhost:1337/hello_craft
Hello! and welcome to Cloud Code (Express) Functions --from Craft Team%
```
<br/>
#### 3.5 Parse Dashboard
Parse Dashboard is a standalone dashboard for managing your Parse Server apps.
Your app's Parse dashboard is accessible at http://localhost:1337/dashboard
<br/><br/>
# Helpful Scripts
These scripts can help you to develop your app for Cloud Code:
`npm run dev` will start your Parse Server in development mode (recommended when working on local).<br/>
`npm start` will start your Parse Server in production mode.<br/>
`npm run watch` will start your Parse Server and restart if you make any changes.<br/>
`npm run lint` will check the linting of your cloud code, tests and index.js, as defined in .eslintrc.json.<br/>
`npm run lint-fix` will attempt fix the linting of your cloud code, tests and index.js.<br/>
`npm run prettier` will help improve the formatting and layout of your cloud code, tests and index.js, as defined in .prettierrc.<br/>
`npm run test` will run any tests that are written in /spec.<br/>
`npm run coverage` will run tests and check coverage. Output is available in the /coverage folder.
<br/>
# Using the Job Scheduler
This library is a minimalist tool that fetches all jobs scheduled objects and schedules cron tasks that will run the scheduled jobs.
Simply create your job, for example
```javascript
Parse.Cloud.job("myJob", (request) => {
// params: passed in the job call
// headers: from the request that triggered the job
// log: the ParseServer logger passed in the request
// message: a function to update the status message of the job object
const { params, headers, log, message } = request;
message("I just started");
return doSomethingVeryLong(request);
});
```
Then, go to your app, ```Craft > My Apps > Your App > Dashboard > Jobs > Schedule a Job```
, and schedule that job (`myjob`) you have just created.
<br/><br/>
# Updating and Deploying your changes
All changes to your code (i.e. pushing/merging code to master) will be automatically deploy via Gitlab CI/CD workflow.
To check if your deployment is finished and Cloud Code is up and running, pls use this URL to get the status:
```bash
<your cloud code URL>/health
```
And it will response:
```bash
{"status":"ok"}
```
<br/>
# Running on Remote Local using Gitpod
Gitpod is an open source Cloud IDE and developer platform automating the provisioning of ready-to-code development environments. It streamlines developer workflows by providing prebuilt, collaborative development environments in your browser.
Designed for applications running in the cloud, Gitpod frees engineering teams from the friction of manually setting-up local dev environments, saving dozens of hours and enabling a new level of collaboration to create applications much more quickly than ever before.
Free Gitpod access comes with free 50 hours/month access
For more info, please visit gitpod.io
Your Cloud Code repo is already integrated with Stratpoint's Gitlab and ready to use, just type this URL format in your browser:
```https://gitpod.io/#https://your-full-repo-url```
For example:
```https://gitpod.io/#https://gitlab.stratpoint.dev/craft/xxxxx/xxxxx/your-project-name```
<br/>
# APIs and SDKs
Use the REST API, GraphQL API or any of the Parse SDKs to see and test your Cloud Code in action. It comes with a variety of SDKs to cover most common ecosystems and languages, such as JavaScript, Swift, ObjectiveC and Android just to name a few.
The following shows example requests when interacting with a local deployment of Cloud Code. If you want to test the deployed Craft Cloud Code, change the URL accordingly.
For full list of SDKs and Libraries for your Frontend apps, please visit https://parseplatform.org/#sdks
### REST API
Save object:
```sh
curl -X POST \
-H "X-Parse-Application-Id: YOUR_APP_ID" \
-H "X-Parse-Rest-Api-Key: YOUR_REST_API_KEY" \
-H "Content-Type: application/json" \
-d '{"score":1337}' \
http://localhost:1337/parse/classes/GameScore
```
Call Cloud Code function:
```sh
curl -X POST \
-H "X-Parse-Application-Id: YOUR_APP_ID" \
-H "X-Parse-Rest-Api-Key: YOUR_REST_API_KEY" \
-H "Content-Type: application/json" \
-d "{}" \
http://localhost:1337/parse/functions/hello
```
### JavaScript
```js
// Initialize SDK
Parse.initialize("YOUR_APP_ID", "YOUR_JAVASCRIPT_KEY");
Parse.serverURL = "http://localhost:1337/parse";
// Save object
const obj = new Parse.Object("GameScore");
obj.set("score", 1337);
await obj.save();
// Query object
const query = new Parse.Query("GameScore");
const objAgain = await query.get(obj.id);
```
### Android
```java
// Initialize SDK in the application class
Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
.applicationId("YOUR_APP_ID")
.clientKey("YOUR_CLIENT_KEY")
.server("http://localhost:1337/parse/") // '/' important after 'parse'
.build());
// Save object
ParseObject obj = new ParseObject("TestObject");
obj.put("foo", "bar");
obj.saveInBackground();
```
### iOS / tvOS / iPadOS / macOS (Swift)
```swift
// Initialize SDK in AppDelegate
Parse.initializeWithConfiguration(ParseClientConfiguration(block: {
(configuration: ParseMutableClientConfiguration) -> Void in
configuration.server = "http://localhost:1337/parse/" // '/' important after 'parse'
configuration.applicationId = "YOUR_APP_ID"
configuration.clientKey = @"parseClientKey"
}))
```
/*
* Simple Parse Cloud Code Example
*/
Parse.Cloud.define("hello_craft", () => {
return "Hello! and welcome to Cloud Code (Parse) Functions --from Craft Team";
});
Parse.Cloud.define("hello", (req) => {
req.log.info(req);
return "Hi";
});
Parse.Cloud.define("asyncFunction", async (req) => {
await new Promise((resolve) => setTimeout(resolve, 1000));
req.log.info(req);
return "Hi async";
});
Parse.Cloud.beforeSave("Test", () => {
throw new Parse.Error(9001, "Saving test objects is not available.");
});
/*
*** NOTE: PLEASE DO NOT EDIT THIS FILE ***
*
*/
const args = process.argv || [];
const test = args.some((arg) => arg.includes("jasmine"));
if (!test) {
// Import the library
const JobsScheduler = require("@brewery/parse-job-scheduler");
// Initialize a Parse instance
JobsScheduler.init({
serverURL: process.env.SERVER_URL || "http://localhost:1337/parse",
appId: process.env.APP_ID || "myAppId",
masterKey: process.env.MASTER_KEY || "masterKey",
});
// Recreates all crons when the server is launched
JobsScheduler.recreateSchedule();
// Recreates schedule when a job schedule has changed
Parse.Cloud.afterSave("_JobSchedule", async (request) => {
JobsScheduler.recreateSchedule(request.object);
});
// Destroy schedule for removed job
Parse.Cloud.afterDelete("_JobSchedule", async (request) => {
JobsScheduler.destroySchedule(request.object);
});
}
require("./functions");
require("./job-scheduler");
/*
* If you want to use Express-based Cloud Code,
* exporting of module.exports.app is required.
* We mount it automaticaly to the Parse Server Deployment (in ./index.js).
* If you don't want to use it just comment module.exports.app
*/
module.exports.express = require("../express");
/*
* Express-based Cloud Code Example
*/
const express = require("express");
const app = express();
app.get("/hello-craft", (req, res) => {
res.send(
"Hello! and welcome to Cloud Code (Express) Functions --from Craft Team"
);
});
/*
* Exporting of module.exports = app is required.
* we mount it automatically to the Parse Server Deployment (in ./index.js).
*/
module.exports = app;
index.js 0 → 100644
/*
*** NOTE: PLEASE DO NOT EDIT THIS FILE ***
*
*/
require("dotenv").config();
const path = require("path");
const express = require("express");
const cors = require("cors");
const { default: ParseServer, ParseGraphQLServer } = require("parse-server");
const ParseDashboard = require("parse-dashboard");
const args = process.argv || [];
const test = args.some((arg) => arg.includes("jasmine"));
const config = require("./parse-config");
const databaseUri = process.env.DATABASE_URI;
if (!databaseUri) {
console.log("DATABASE_URI not specified, falling back to localhost.");
}
const mountPath = process.env.PARSE_MOUNT || "/parse";
const port = process.env.PORT || 1337;
const app = express();
app.enable("trust proxy");
app.use(express.json());
if (process.env.IS_DEVELOPMENT === false && !test) {
/* New Relic setup */
const newrelicParseServerName = process.env.NEWRELIC_PARSE_SERVER_NAME;
const newrelicLicenseKey = process.env.NEWRELIC_LICENSE_KEY;
if (newrelicLicenseKey && newrelicParseServerName) {
// Tag the user request for analytics purposes
const newrelic = require("newrelic");
const instrumentedPath = new RegExp("^" + mountPath + "((?!/users/me).)*$");
app.use(instrumentedPath, (req, res, next) => {
const sessionToken =
req.headers["x-parse-session-token"] || req.body["_SessionToken"];
if (sessionToken) {
const parseServerUrl =
req.protocol + "://" + req.get("host") + mountPath;
Parse.initialize(config.appId, config.javascriptKey, config.masterKey);
Parse.serverURL = parseServerUrl;
Parse.User.enableUnsafeCurrentUser();
Parse.User.become(sessionToken, { useMasterKey: true }).then(
(user) => {
newrelic.addCustomAttribute("user_id", user.id);
next();
},
(error) => {
console.log(error);
next();
}
);
} else {
next();
}
});
}
}
app.use(cors());
if (process.env.IS_DEVELOPMENT && !test) {
const users = [
{
user: "admin",
pass: "$2y$12$zkMYmegpI00X2NmNBKHiEuujT6xl7AKWpO/Lx.3d2Gq2K2RBeulzi",
},
];
app.use(
"/dashboard",
new ParseDashboard(
{
apps: [
{
serverURL: config.serverURL,
graphQLServerURL: config.graphQLServerURL,
appId: config.appId,
masterKey: config.masterKey,
appName: "my-dev-parse-server",
},
],
users,
useEncryptedPasswords: true,
},
process.env.IS_DEVELOPMENT
)
);
}
// Serve static assets from the /public folder
app.use(express.static(path.join(__dirname, "/public")));
if (!test) {
// Mount your cloud express app
const api = new ParseServer(config);
app.use("/", require("./cloud/main").express);
// Serve the Parse API on the /parse URL prefix
app.use(mountPath, api.app);
const httpServer = require("http").createServer(app);
httpServer.listen(port, () => {
console.log(`REST API Running on http://localhost:${port}/parse`);
});
if (process.env.IS_DEVELOPMENT) {
const parseGraphQLServer = new ParseGraphQLServer(api, {
graphQLPath: "/graphql",
});
parseGraphQLServer.applyGraphQL(app);
console.log(
`Parse Dashboard Running on http://localhost:${port}/dashboard.
**From Dashboard you can access GraphQL playground, go to Core > API Console > GraphQL Console`
);
}
// This will enable the Live Query real-time server
ParseServer.createLiveQueryServer(httpServer);
}
module.exports = {
app,
config,
};
"use strict";
/*
*** NOTE: PLEASE DO NOT EDIT THIS FILE ***
*
*/
export const config = {
/**
* Array of application names.
*/
app_name: [process.env.NEWRELIC_PARSE_SERVER_NAME],
/**
* Your New Relic license key.
*/
license_key: process.env.NEWRELIC_LICENSE_KEY,
/**
* This setting controls distributed tracing.
* Distributed tracing lets you see the path that a request takes through your
* distributed system. Enabling distributed tracing changes the behavior of some
* New Relic features, so carefully consult the transition guide before you enable
* this feature: https://docs.newrelic.com/docs/transition-guide-distributed-tracing
* Default is true.
*/
distributed_tracing: {
/**
* Enables/disables distributed tracing.
*
* @env NEW_RELIC_DISTRIBUTED_TRACING_ENABLED
*/
enabled: true,
},
logging: {
/**
* Level at which to log. 'trace' is most useful to New Relic when diagnosing
* issues with the agent, 'info' and higher will impose the least overhead on
* production applications.
*/
level: "info",
},
/**
* When true, all request headers except for those listed in attributes.exclude
* will be captured for all traces, unless otherwise specified in a destination's
* attributes include/exclude lists.
*/
allow_all_headers: true,
attributes: {
/**
* Prefix of attributes to exclude from all destinations. Allows * as wildcard
* at end.
*
* NOTE: If excluding headers, they must be in camelCase form to be filtered.
*
* @env NEW_RELIC_ATTRIBUTES_EXCLUDE
*/
exclude: [
"request.headers.cookie",
"request.headers.authorization",
"request.headers.proxyAuthorization",
"request.headers.setCookie*",
"request.headers.x*",
"response.headers.cookie",
"response.headers.authorization",
"response.headers.proxyAuthorization",
"response.headers.setCookie*",
"response.headers.x*",
],
},
};
{
"name": "my-dev-parse-server",
"version": "1.0.0",
"description": "My Development Parse API Server with Cloud Code",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/ParsePlatform/parse-server.git"
},
"license": "MIT",
"dependencies": {
"@brewery/parse-job-scheduler": "^1.0.1",
"cors": "^2.8.5",
"dotenv": "^9.0.2",
"newrelic": "^7.4.0",
"parse": "^3.2.0",
"parse-dashboard": "^2.1.0",
"parse-server": "^4.5.0",
"parse-server-email-template-adapter": "^1.0.2"
},
"devDependencies": {
"@babel/core": "^7.14.3",
"@babel/eslint-parser": "^7.14.3",
"@babel/preset-env": "^7.14.2",
"babel-watch": "^7.4.1",
"concurrently": "^6.1.0",
"eslint": "^7.26.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "2.23.2",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "5.1.0",
"jasmine": "3.7.0",
"nodemon": "^2.0.7",
"nyc": "15.1.0"
},
"scripts": {
"dev": "concurrently --kill-others 'npm run server'",
"server": "VERBOSE=1 nodemon ./index.js",
"start": "nodemon ./index.js",
"lint": "eslint --cache ./cloud && eslint --cache index.js && eslint --cache ./spec",
"lint-fix": "eslint --cache --fix ./cloud && eslint --cache --fix index.js && eslint --cache --fix ./spec",
"test": "jasmine",
"coverage": "nyc jasmine",
"prettier": "prettier --write '{cloud,spec}/{**/*,*}.js' 'index.js'",
"watch": "babel-watch index.js"
},
"engines": {
"node": ">=4.3"
}
}
/*
* PLEASE NOTE THAT THESE CONFIGURATIONS ARE FOR LOCAL DEVELOPMENT ONLY.
* ANY CHANGES HERE MAY NOT REFLECT ON YOUR DEPLOYED PROJECT IN CRAFT.
*
*/
module.exports = {
databaseURI:
process.env.DATABASE_URI || "postgres://user:pass@localhost:5432/dbname",
appId: process.env.APP_ID || "myAppId",
clientKey: process.env.CLIENT_KEY || "myClientKey",
masterKey: process.env.MASTER_KEY || "masterKey", //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || "http://localhost:1337/parse",
javascriptKey: process.env.JAVASCRIPT_KEY || "myJSKey",
restAPIKey: process.env.REST_API_KEY || "restAPIKey",
cloud: process.env.PARSE_CLOUD_CODE || "./cloud/main.js",
liveQuery: {
classNames: [], // List of classes to support for query subscriptions example: [ 'Posts', 'Comments' ]
},
verbose: false,
};
{
"Servers": {
"1": {
"Name": "Gitpod PostgreSQL",
"Group": "Default Servers",
"Port": 5432,
"Username": "postgres",
"Host": "127.0.0.1",
"SSLMode": "prefer",
"MaintenanceDB": "postgres"
}
}
}
#!/bin/bash
set -ex
eval $(gp env --export)
if [ -z "$PGADMIN_DEFAULT_EMAIL" ] ; then
gp env PGADMIN_DEFAULT_EMAIL=pgadmin@gitpod.io
fi
if [ -z "$PGADMIN_DEFAULT_PASSWORD" ] ; then
gp env PGADMIN_DEFAULT_PASSWORD=$(date | md5sum | head -c 32)
fi
eval $(gp env --export)
export AUTOMATED=1
export PGADMIN_SETUP_EMAIL=$PGADMIN_DEFAULT_EMAIL
export PGADMIN_SETUP_PASSWORD=$PGADMIN_DEFAULT_PASSWORD
export PGADMIN_CONFIG_DEFAULT_SERVER=0.0.0.0
export PGADMIN_LISTEN_ADDRESS=0.0.0.0
export PGADMIN_SERVER_JSON_FILE=./pgadmin4/servers.json
/home/gitpod/.pyenv/shims/pgadmin4 &
# wait for pgadmin to start
while ! nc -z localhost 5050; do
sleep 1
done
SETUP_SCRIPT_PATH=$(find /home/gitpod/.pyenv/versions -name setup.py | grep pgadmin4)
/home/gitpod/.pyenv/shims/python $SETUP_SCRIPT_PATH \
--load-servers $PGADMIN_SERVER_JSON_FILE \
--user $PGADMIN_DEFAULT_EMAIL
echo "pgAdmin4 configured with credentials:
$(gp env | grep PGADMIN_DEFAULT)"
public/brewery.png

147 KiB

public/craft.png

31.2 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment