Skip to content

Commit

Permalink
Support ssl parse-server and add yongjhih/parse-server:git
Browse files Browse the repository at this point in the history
  • Loading branch information
yongjhih committed Apr 24, 2016
1 parent e7b9a43 commit a7c01b6
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 75 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ node_modules

# Vim
*.swp
*.swo

*.pem
account_key.json
Expand Down
15 changes: 0 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,4 @@ EXPOSE $PORT
VOLUME $CLOUD_CODE_HOME
ENV NODE_PATH .

RUN apt-get update && \
apt-get install -y --no-install-recommends openssh-server && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

ENV SSH_PORT 2022
EXPOSE $SSH_PORT

ADD ssh-add-key /sbin/

RUN useradd -s /bin/bash git
RUN echo "git ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

ADD docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["npm", "start"]
53 changes: 28 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,16 @@ $ docker run -d \
-e APP_ID=${PARSE_APP_ID} \
-e MASTER_KEY=${PARSE_MASTER_KEY} \
-p 1337:1337 \
-p 2022:22 \
--link mongo \
--name parse-server \
yongjhih/parse-server

$ docker run -d \
-p 2022:22 \
--link parse-server \
--name parse-cloud-code-git \
yongjhih/parse-server:git

# Test parse-server
$ curl -X POST \
-H "X-Parse-Application-Id: {appId}" \
Expand All @@ -74,14 +79,14 @@ $ docker run -d \
--link parse-server \
--name parse-dashboard \
yongjhih/parse-dashboard
#The above command will asuume you will later create a ssh
#and log into the dashboard remotely in production.
# However, to see the dashboard instanly using either
# localhost:4040 or someip:4040(if hosted somewhere remotely)
#then you need to add extra option to allowInsecureHTTP like
#It is also required that you create username and password
#before accessing the portal else you cant get in

# The above command will asuume you will later create a ssh
# and log into the dashboard remotely in production.
# However, to see the dashboard instanly using either
# localhost:4040 or someip:4040(if hosted somewhere remotely)
# then you need to add extra option to allowInsecureHTTP like
# It is also required that you create username and password
# before accessing the portal else you cant get in

$ docker run -d \
-e APP_ID=$(PARSE_APP_ID)\
Expand Down Expand Up @@ -111,13 +116,13 @@ Deploy parse-cloud-code via git:
[![Screencast - git](https://github.com/yongjhih/docker-parse-server/raw/master/art/docker-parse-server-git.gif)](https://youtu.be/9YwWbiRyPUU)

```sh
#This command wil create a SSH keys for you as
# ~/.ssh/id_rsa.pub and another private key.
#you can leave the options balnk by pressing enter.
# This command wil create a SSH keys for you as
# ~/.ssh/id_rsa.pub and another private key.
# you can leave the options balnk by pressing enter.

$ssh-keygen -t rsa
$ ssh-keygen -t rsa

$ docker exec -i parse-server ssh-add-key < ~/.ssh/id_rsa.pub
$ docker exec -i parse-cloud-code-git ssh-add-key < ~/.ssh/id_rsa.pub

$ git clone ssh://git@localhost:2022/parse-cloud-code
$ cd parse-cloud-code
Expand All @@ -144,7 +149,6 @@ $ docker run -d \
-e APP_ID=${PARSE_APP_ID} \
-e MASTER_KEY=${PARSE_MASTER_KEY} \
-p 1337:1337 \
-p 2022:22 \
--name parse-server \
yongjhih/parse-server
```
Expand All @@ -167,7 +171,6 @@ $ docker run -d \
-e APP_ID={appId} \
-e MASTER_KEY={masterKey} \
-p 1337:1337 \
-p 2022:22 \
--link mongo \
--name parse-server \
yongjhih/parse-server
Expand All @@ -186,7 +189,6 @@ $ docker run -d \
-e APP_ID=${PARSE_APP_ID} \
-e MASTER_KEY=${PARSE_MASTER_KEY} \
-p 1337:1337 \
-p 2022:22 \
--link mongo \
--name parse-server \
yongjhih/parse-server
Expand All @@ -201,7 +203,6 @@ $ docker run -d \
-e APP_ID=${PARSE_APP_ID} \
-e MASTER_KEY=${PARSE_MASTER_KEY} \
-p 1337:1337 \
-p 2022:22 \
--link mongo \
--name parse-server \
yongjhih/parse-server:2.2.7
Expand All @@ -217,7 +218,6 @@ $ docker run -d \
-e APP_ID=${PARSE_APP_ID} \
-e MASTER_KEY=${PARSE_MASTER_KEY} \
-p 1337:1337 \
-p 2022:22 \
--link mongo \
--name parse-server \
yongjhih/parse-server:dev
Expand All @@ -233,17 +233,20 @@ And, up other containers without parse-dashboard:
$ APP_ID=myAppId MASTER_KEY=myMasterKey docker-compose up -d -f docker-compose-without-dashboard.yml
```

### Usage of letsencrypt for parse-dashboard with https certificated domain
### Usage of https certificated domain with letsencrypt

```sh
$ git clone https://github.com/yongjhih/docker-parse-server
$ cd docker-parse-server

$ USER1=yongjhih \
USER1_PASSWORD=yongjhih \
[email protected] \
LETSENCRYPT_HOST=yongjhih.example.com \
VIRTUAL_HOST=yongjhih.example.com \
PARSE_DASHBOARD_VIRTUAL_HOST=parse.example.com \
PARSE_DASHBOARD_LETSENCRYPT_HOST=parse.example.com \
[email protected] \
PARSE_SERVER_VIRTUAL_HOST=api.example.com \
PARSE_SERVER_LETSENCRYPT_HOST=api.example.com \
[email protected] \
APP_ID=myAppId MASTER_KEY=myMasterKey docker-compose -f docker-compose-le.yml up
```

Expand All @@ -265,7 +268,7 @@ sed -i -- '/- "80:80"/d' docker-compose-le.yml
Without docker-compose:

* Re/create parse-cloud-code volume container: `docker create -v /parse/code --name parse-cloud-code {username}/parse-cloud-code /bin/true`
* Re/create parse-server container with volume: `docker run -d --volumes-from parse-cloud-code APP_ID={appId} -e MASTER_KEY={masterKey} -p 1337:1337 -p 2022:22 --link mongo yongjhih/parse-server`
* Re/create parse-server container with volume: `docker run -d --volumes-from parse-cloud-code APP_ID={appId} -e MASTER_KEY={masterKey} -p 1337:1337 --link mongo yongjhih/parse-server`

With docker-compose.yml:

Expand Down Expand Up @@ -361,7 +364,7 @@ parse-cloud-code:
## Add ssh-key for git

```sh
$ docker exec -i parse-server ssh-add-key < ~/.ssh/id_rsa.pub
$ docker exec -i parse-cloud-cloud-git ssh-add-key < ~/.ssh/id_rsa.pub
```

Import keys from github:
Expand Down
36 changes: 29 additions & 7 deletions docker-compose-le.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ parse-server:
image: yongjhih/parse-server
ports:
- "1337:1337"
- "2022:22"
environment:
PORT: 1337
DATABASE_URI: $DATABASE_URI
APP_ID: $APP_ID
MASTER_KEY: $MASTER_KEY
Expand Down Expand Up @@ -34,7 +34,7 @@ parse-server:
ALLOW_CLIENT_CLASS_CREATION: $ALLOW_CLIENT_CLASS_CREATION # true
APP_NAME: $APP_NAME
PUBLIC_SERVER_URL: $PUBLIC_SERVER_URL
TRUST_PROXY: $TRUST_PROXY
TRUST_PROXY: $TRUST_PROXY
S3_ACCESS_KEY: $S3_ACCESS_KEY
S3_SECRET_KEY: $S3_SECRET_KEY
S3_BUCKET: $S3_BUCKET
Expand All @@ -43,19 +43,40 @@ parse-server:
GCP_KEYFILE_PATH: $GCP_KEYFILE_PATH
GCS_BUCKET: $GCS_BUCKET
GCS_DIRECT: $GCS_DIRECT
VIRTUAL_HOST: $PARSE_SERVER_VIRTUAL_HOST
LETSENCRYPT_HOST: $PARSE_SERVER_LETSENCRYPT_HOST
VIRTUAL_HOST: $PARSE_SERVER_VIRTUAL_HOST
LETSENCRYPT_HOST: $PARSE_SERVER_LETSENCRYPT_HOST
LETSENCRYPT_EMAIL: $PARSE_SERVER_LETSENCRYPT_EMAIL
links:
- mongo
volumes_from:
- parse-cloud-code
volumes:
- /parse/cloud

parse-cloud-code:
#build: cloud/.
image: yongjhih/parse-cloud-code
volumes:
- /parse/cloud
command: "ls /parse/cloud"

git:
image: yongjhih/parse-server:git
ports:
- "2022:22"
environment:
PORT: 22
#WORKTREE: $GIT_WORKTREE
#REPO_PATH: $GIT_REPO_PATH
volumes_from:
- parse-server

parse-cloud-code:
image: yongjhih/parse-cloud-code
volumes:
- /parse/cloud
command: "ls /parse/cloud"

mongo:
image: mongo
ports:
Expand Down Expand Up @@ -89,9 +110,10 @@ parse-dashboard:
PARSE_DASHBOARD_ALLOW_INSECURE_HTTP: $PARSE_DASHBOARD_ALLOW_INSECURE_HTTP
USER1: $USER1
USER1_PASSWORD: $USER1_PASSWORD
VIRTUAL_HOST: $VIRTUAL_HOST
LETSENCRYPT_HOST: $LETSENCRYPT_HOST
LETSENCRYPT_EMAIL: $LETSENCRYPT_EMAIL
VIRTUAL_HOST: $PARSE_DASHBOARD_VIRTUAL_HOST
LETSENCRYPT_HOST: $PARSE_DASHBOARD_LETSENCRYPT_HOST
LETSENCRYPT_EMAIL: $PARSE_DASHBOARD_LETSENCRYPT_EMAIL
PORT: 4040
ports:
- "4040:4040"
# volumes:
Expand Down
18 changes: 17 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ parse-server:
image: yongjhih/parse-server
ports:
- "1337:1337"
- "2022:22"
environment:
PORT: 1337
DATABASE_URI: $DATABASE_URI
APP_ID: $APP_ID
MASTER_KEY: $MASTER_KEY
Expand Down Expand Up @@ -47,12 +47,27 @@ parse-server:
- mongo
volumes_from:
- parse-cloud-code
volumes:
- /parse/cloud

parse-cloud-code:
#build: cloud/.
image: yongjhih/parse-cloud-code
volumes:
- /parse/cloud
command: "ls /parse/cloud"

git:
image: yongjhih/parse-server:git
ports:
- "2022:22"
environment:
PORT: 22
#WORKTREE: $GIT_WORKTREE
#REPO_PATH: $GIT_REPO_PATH
volumes_from:
- parse-server

mongo:
image: mongo
ports:
Expand All @@ -62,6 +77,7 @@ mongo:
# command: "--smallfiles --logpath=/dev/null --setParameter failIndexKeyTooLong=false --rest --auth"
command: "--smallfiles --logpath=/dev/null --setParameter failIndexKeyTooLong=false"
# ref. http://www.diogogmt.com/running-mongodb-with-docker-and-compose/

mongo-data:
image: mongo
volumes:
Expand Down
25 changes: 0 additions & 25 deletions docker-entrypoint.sh

This file was deleted.

27 changes: 27 additions & 0 deletions docker/git/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM debian:jessie

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update && \
apt-get install -y --no-install-recommends git openssh-server && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
sed -i "s/UsePrivilegeSeparation.*/UsePrivilegeSeparation no/g" /etc/ssh/sshd_config

# Missing privilege separation directory: /var/run/sshd

ENV PORT 22
EXPOSE $PORT

ENV WORKTREE "/parse/cloud"
ENV REPO_PATH "/parse-cloud-code"

ADD ssh-add-key /sbin/

RUN useradd -s /bin/bash git
RUN echo "git ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

ADD docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]

CMD ["/usr/sbin/sshd", "-D"]
23 changes: 23 additions & 0 deletions docker/git/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

set -e

if [ ! -d ${REPO_PATH} ]; then
mkdir -p ${REPO_PATH}

git init --bare ${REPO_PATH} > /dev/null

cat << EOF > ${REPO_PATH}/hooks/post-receive
#!/bin/bash
unset GIT_INDEX_FILE
git --work-tree="${WORKTREE}" clean -df
git --work-tree="${WORKTREE}" checkout -f
EOF

chmod a+x ${REPO_PATH}/hooks/post-receive > /dev/null

chown -R git:git ${REPO_PATH} > /dev/null
chown -R git:git "$WORKTREE" > /dev/null
fi

exec "$@"
File renamed without changes.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ var api = new ParseServer({

var app = express();

if(process.env.TRUST_PROXY == 1) {
console.log("trusting proxy");
if (process.env.TRUST_PROXY !== "false") {
console.log("trusting proxy: " + process.env.TRUST_PROXY);
app.enable('trust proxy');
}

Expand Down

0 comments on commit a7c01b6

Please sign in to comment.