Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serving home app as standalone web app (docker) #264

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.git
doc
app-cc-home-clone.zip
app-cc-home
github.css
LICENSE
profile.json
README_ja.md
README.md
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dst
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM nginx:1.21

COPY build.sh /docker-entrypoint.d/30-render-template.sh
RUN chmod +x /docker-entrypoint.d/30-render-template.sh && \
mkdir -p /opt/src/app-cc-home && mkdir -p /opt/dst/app-cc-home

WORKDIR /opt/src/app-cc-home
ENV BUILD_DIR /opt
ADD src .

COPY nginx-app-cc-home.conf /etc/nginx/conf.d/default.conf
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,72 @@ If you want to deploy your own HomeApp which supports Google Login, make sure yo
1. Click "Google".
1. Enter email address.
1. Click "Register".


# Using nginx to serve

To serve home app with nginx, you can use build script to prepare stuff.

```bash
CELL_NAME=app-cc-home UNIT_FQDN=demo.personium.io bash ./build.sh 3> build.log
```

And then, you can use built stuff in `dst` folder to serve home app.

To serve `dst` folder with nginx, you have to create a nginx configuration file on `/etc/nginx/sites-available/`. Examples are shown below.

```bash
sudo vim /etc/nginx/sites-available/app-cc-home.conf
```

```conf
server {
listen 80 default_server;

location /__/ {
add_header Access-Control-Allow-Origin '*' always;
alias /opt/dst/app-cc-home/; # change path to your dst folder
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
```

To enable serving, you can do with below command.

```bash
sudo ln -s /etc/nginx/sites-available/app-cc-home.conf /etc/nginx/sites-enabled/
```

And then, restart nginx to apply configuration.

```bash
sudo systemctl restart nginx
```

## build variables

You can specify below environment variables to configure builds.

|env|description|example|
|:--|:--|:--|
|CELL_NAME|Specify home app cell name. If `HOME_APP_CELL_URL` is not specified, this varible is used instead. |`app-cc-home`|
|UNIT_FQDN|Specify unit FQDN which home app is deployed. If `HOME_APP_CELL_URL` is not specified, this variable is used instead.|`pds.example.com`|
|HOME_APP_CELL_URL|Specify home app cell url ending with `/`.|`https://app-cc-home.pds.example.com/`|
|MARKETLIST_ENDPOINT|Specify market list (OData) endpoint url.|`https://market.pds.example.com/OData/applist/Apps`|
|APPDIRECTORY_ENDPOINT|Specify app directory (OData) endpoint url.|`https://directory.pds.example.com/app-uc-directory/OData/directory`|


# Using docker to serve
dixonsiu marked this conversation as resolved.
Show resolved Hide resolved

You can serve your home app with docker. To use docker to serve, you can use below command.

```bash
docker build . -t app-cc-home
docker run -d -e HOME_APP_CELL_URL=<CELL_URL_TO_HOMEAPP> app-cc-home
```

To customize launch configuration, you can specify above build variables.
36 changes: 36 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

set -e

ME=$(basename $0)

render_template() {
local current_dir="$(pwd)"
local template_dir="${BUILD_DIR:-$current_dir}/src"
local suffix=""
local output_dir="${BUILD_DIR:-$current_dir}/dst"

mkdir -p $output_dir

local template defined_envs relative_path output_path subdir
defined_envs=$(printf '${%s} ' $(env | cut -d= -f1))
[ -d "$template_dir" ] || return 0
if [ ! -w "$output_dir" ]; then
echo >&3 "$ME: ERROR: $template_dir exists, but $output_dir is not writable"
return 0
fi

for f in $(find $template_dir -type f); do
relative_path="${f#$template_dir/}"
output_path="$output_dir/${relative_path}"
subdir=$(dirname "$relative_path")
# create a subdirectory where the template file exists
mkdir -p "$output_dir/$subdir"
echo >&3 "$ME: Running envsubst on $f to $output_path"
envsubst "$defined_envs" < $f > "$output_path";
done
}

render_template

exit 0
Binary file removed html/img/Thumbs.db
Binary file not shown.
Binary file removed html/img/clean.JPG
Binary file not shown.
13 changes: 13 additions & 0 deletions nginx-app-cc-home.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
server {
listen 80 default_server;

location /__/ {
add_header Access-Control-Allow-Origin '*' always;
alias /opt/dst/app-cc-home/;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
6 changes: 3 additions & 3 deletions authform/authform_new.html → src/authform/authform_new.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
<html>
<head>
<link href="https://use.fontawesome.com/releases/v5.0.8/css/all.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://app-cc-home.demo.personium.io/__/authform/login.css">
<link rel="stylesheet" type="text/css" href="https://app-cc-home.demo.personium.io/__/authform/personium.css">
<link rel="stylesheet" type="text/css" href="${HOME_APP_CELL_URL}__/authform/login.css">
<link rel="stylesheet" type="text/css" href="${HOME_APP_CELL_URL}__/authform/personium.css">

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script defer src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/i18next/8.4.3/i18next.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/i18next-xhr-backend/1.5.1/i18nextXHRBackend.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/i18next-browser-languagedetector/2.0.0/i18nextBrowserLanguageDetector.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-i18next/1.2.0/jquery-i18next.min.js"></script>
<script defer src="https://app-cc-home.demo.personium.io/__/authform/sample.js"></script>
<script defer src="${HOME_APP_CELL_URL}__/authform/sample.js"></script>

<title>OAuth2 authorization endpoint</title>
</head>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<html>
<head>
<link href="https://use.fontawesome.com/releases/v5.0.8/css/all.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://app-cc-home.demo.personium.io/__/authform/login.css">
<link rel="stylesheet" type="text/css" href="https://app-cc-home.demo.personium.io/__/authform/personium.css">
<link rel="stylesheet" type="text/css" href="${HOME_APP_CELL_URL}__/authform/login.css">
<link rel="stylesheet" type="text/css" href="${HOME_APP_CELL_URL}__/authform/personium.css">

<script defer src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>

Expand Down
File renamed without changes.
File renamed without changes.
Loading