Skip to content

Commit

Permalink
Use injected configuration from Nginx at runtime instead of build time (
Browse files Browse the repository at this point in the history
#30)

* Use envsubst and nginx templates to generate nginx configs which can substitute environment variables and inject into the index.html file

* Fix path in dockerfile. Add .gitignore and .env.example files. Fix nginx-linux template.

* Add all environment variables. Add prefix to all environment variables. Update scripts to attempt to substitute all environment variables with the prefix

* Setup dockerfile to execute a bash script. use env.example for fetching environment variables in development

* Toggle features based on injected configs. Fix nginx template substitution script.

* Update env.example file

* Remove debug code from start-nginx.sh

* Fix nginx config templates by adding quotes by default. Fix sed regex to include numerals. Toggle social login buttons on Login page based on the config.

* Update rapid api environment variable name. Toggle oauth buttons based on config in SignUp page. Update .env.example to be a union of server and client environment variables

* Adding a Map disabled message on Map widget

* Adding links to Privacy policy and TNC

* Use REACT_APP_ env variables with higher priority over injected config variables for toggling features

* Update netlify.toml by commenting out the build environment variables

* Remove env variables not required by the client

* Remove start-storybook entry from package.json

* Fix netlify.toml. Fallback algolia configs

* Add contexts to netlify.toml for successful deploys. Swith to using APPSMITH_MARKETPLACE_URL as the toggle for RapidAPI feature on the client. Remove comments in nginx config templates. Fix template used in dockerfile.

Co-authored-by: Satbir Singh <apple@apples-MacBook-Pro.local>
Co-authored-by: Satbir Singh <satbir121@gmail.com>
  • Loading branch information
3 people authored Jul 7, 2020
1 parent d85376b commit 94b2831
Show file tree
Hide file tree
Showing 34 changed files with 821 additions and 629 deletions.
50 changes: 50 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Rename this to .env
# Note: Please donot include quotes (double or single) in the values

# Sentry
APPSMITH_SENTRY_DSN=

# Hotjar
APPSMITH_HOTJAR_HJID=
APPSMITH_HOTJAR_HJSV=

# Google OAuth
APPSMITH_OAUTH2_GOOGLE_CLIENT_ID=
APPSMITH_OAUTH2_GOOGLE_CLIENT_SECRET=

# Github OAuth
APPSMITH_OAUTH2_GITHUB_CLIENT_ID=
APPSMITH_OAUTH2_GITHUB_CLIENT_SECRET=

# Segment
APPSMITH_SEGMENT_KEY=

# RapidAPI
APPSMITH_RAPID_API_KEY_VALUE=
APPSMITH_MARKETPLACE_URL=

# Optimizely
APPSMITH_OPTIMIZELY_KEY=

# Algolia Search (Docs)
APPSMITH_ALGOLIA_API_ID=
APPSMITH_ALGOLIA_API_KEY=
APPSMITH_ALGOLIA_SEARCH_INDEX_NAME=

#Client log level (debug | error)
APPSMITH_CLIENT_LOG_LEVEL=

# GOOGLE client API KEY
APPSMITH_GOOGLE_MAPS_API_KEY=

# Email server
APPSMITH_MAIL_ENABLED=
APPSMITH_MAIL_HOST=
APPSMITH_MAIL_PORT=
APPSMITH_MAIL_USERNAME=
APPSMITH_MAIL_PASSWORD=

# Email server feature toggles
# true | false values
APPSMITH_MAIL_SMTP_AUTH=
APPSMITH_MAIL_SMTP_TLS_ENABLED=
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.DS_Store
.idea
*.iml

.env
2 changes: 2 additions & 0 deletions app/client/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ cypress/screenshots
results/

/docker/*.pem
/docker/nginx.conf

5 changes: 3 additions & 2 deletions app/client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
FROM nginx:1.17.9-alpine

COPY ./build /var/www/appsmith
RUN ls -al /var/www/appsmith

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
COPY ./docker/templates/nginx-linux.conf.template /nginx.conf.template
COPY ./docker/start-nginx.sh /start-nginx.sh
CMD ["/start-nginx.sh"]
88 changes: 0 additions & 88 deletions app/client/docker/nginx-linux.conf

This file was deleted.

87 changes: 0 additions & 87 deletions app/client/docker/nginx-mac.conf

This file was deleted.

4 changes: 4 additions & 0 deletions app/client/docker/start-nginx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -ue
cat /nginx.conf.template | envsubst "$(printf '$%s,' $(env | grep -Eo '^APPSMITH_[A-Z0-9_]+'))" | sed -e 's|\${\(APPSMITH_[A-Z0-9_]*\)}||g' | tee /etc/nginx/conf.d/app.conf
exec nginx -g 'daemon off;'
121 changes: 121 additions & 0 deletions app/client/docker/templates/nginx-linux.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
server {
listen 80;
server_name dev.appsmith.com;
client_max_body_size 10m;

gzip on;
gzip_proxied any;

proxy_ssl_server_name on;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header Accept-Encoding "";


sub_filter_once off;
location / {
proxy_pass http://localhost:3000;
sub_filter __APPSMITH_SENTRY_DSN__ '${APPSMITH_SENTRY_DSN}';
sub_filter __APPSMITH_APPSMITH_HOTJAR_HJID__ '${APPSMITH_HOTJAR_HJID}';
sub_filter __APPSMITH_HOTJAR_HJSV__ '${APPSMITH_HOTJAR_HJSV}';
sub_filter __APPSMITH_OAUTH2_GOOGLE_CLIENT_ID__ '${APPSMITH_OAUTH2_GOOGLE_CLIENT_ID}';
sub_filter __APPSMITH_OAUTH2_GITHUB_CLIENT_ID__ '${APPSMITH_OAUTH2_GITHUB_CLIENT_ID}';
sub_filter __APPSMITH_MARKETPLACE_URL__ '${APPSMITH_MARKETPLACE_URL}';
sub_filter __APPSMITH_SEGMENT_KEY__ '${APPSMITH_SEGMENT_KEY}';
sub_filter __APPSMITH_OPTIMIZELY_KEY__ '${APPSMITH_OPTIMIZELY_KEY}';
sub_filter __APPSMITH_ALGOLIA_API_ID__ '${APPSMITH_ALGOLIA_API_ID}';
sub_filter __APPSMITH_ALGOLIA_SEARCH_INDEX_NAME__ '${APPSMITH_ALGOLIA_SEARCH_INDEX_NAME}';
sub_filter __APPSMITH_ALGOLIA_API_KEY__ '${APPSMITH_ALGOLIA_API_KEY}';
sub_filter __APPSMITH_CLIENT_LOG_LEVEL__ '${APPSMITH_CLIENT_LOG_LEVEL}';
sub_filter __APPSMITH_GOOGLE_MAPS_API_KEY__ '${APPSMITH_GOOGLE_MAPS_API_KEY}';
sub_filter __APPSMITH_TNC_PP__ '${APPSMITH_TNC_PP}';
}

location /f {
proxy_pass https://cdn.optimizely.com/;
}

location /api {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_pass https://release-api.appsmith.com;
}

location /oauth2 {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_pass https://release-api.appsmith.com;
}

location /login {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_pass https://release-api.appsmith.com;
}

}

server {
listen 443 ssl http2;
server_name dev.appsmith.com;

ssl_certificate /etc/certificate/dev.appsmith.com.pem;
ssl_certificate_key /etc/certificate/dev.appsmith.com-key.pem;

# include /etc/letsencrypt/options-ssl-nginx.conf;
# ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
gzip on;

proxy_ssl_server_name on;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header Accept-Encoding "";


sub_filter_once off;
location / {
proxy_pass http://localhost:3000;
sub_filter __APPSMITH_SENTRY_DSN__ '${APPSMITH_SENTRY_DSN}';
sub_filter __APPSMITH_HOTJAR_HJID__ '${APPSMITH_HOTJAR_HJID}';
sub_filter __APPSMITH_HOTJAR_HJSV__ '${APPSMITH_HOTJAR_HJSV}';
sub_filter __APPSMITH_OAUTH2_GOOGLE_CLIENT_ID__ '${APPSMITH_OAUTH2_GOOGLE_CLIENT_ID}';
sub_filter __APPSMITH_OAUTH2_GITHUB_CLIENT_ID__ '${APPSMITH_OAUTH2_GITHUB_CLIENT_ID}';
sub_filter __APPSMITH_MARKETPLACE_URL__ '${APPSMITH_MARKETPLACE_URL}';
sub_filter __APPSMITH_SEGMENT_KEY__ '${APPSMITH_SEGMENT_KEY}';
sub_filter __APPSMITH_OPTIMIZELY_KEY__ '${APPSMITH_OPTIMIZELY_KEY}';
sub_filter __APPSMITH_ALGOLIA_API_ID__ '${APPSMITH_ALGOLIA_API_ID}';
sub_filter __APPSMITH_ALGOLIA_SEARCH_INDEX_NAME__ '${APPSMITH_ALGOLIA_SEARCH_INDEX_NAME}';
sub_filter __APPSMITH_ALGOLIA_API_KEY__ '${APPSMITH_ALGOLIA_API_KEY}';
sub_filter __APPSMITH_CLIENT_LOG_LEVEL__ '${APPSMITH_CLIENT_LOG_LEVEL}';
sub_filter __APPSMITH_GOOGLE_MAPS_API_KEY__ '${APPSMITH_GOOGLE_MAPS_API_KEY}';
sub_filter __APPSMITH_TNC_PP__ '${APPSMITH_TNC_PP}';
}

location /f {
proxy_pass https://cdn.optimizely.com/;
}

location /api {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_pass https://release-api.appsmith.com;
}

location /oauth2 {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_pass https://release-api.appsmith.com;
}

location /login {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_pass https://release-api.appsmith.com;
}
}

Loading

0 comments on commit 94b2831

Please sign in to comment.