From 43e75401d72dbe2f4efc6c7177397afabdbca1d6 Mon Sep 17 00:00:00 2001 From: madmath03 Date: Mon, 1 Mar 2021 00:09:42 +0000 Subject: [PATCH] :tada: Fully automate dev setup with Gitpod. This commit implements a fully-automated development setup using Gitpod.io, an online IDE for GitLab, GitHub, and Bitbucket that enables Dev-Environments-As-Code. This makes it easy for anyone to get a ready-to-code workspace for any branch, issue or pull request almost instantly with a single click. :whale: Gitpod docker image with Clojure Signed-off-by: madmath03 :whale: Fix path to GitPod docker image Signed-off-by: madmath03 :whale: Use sudo for setup Signed-off-by: madmath03 :whale: More sudo commands Signed-off-by: madmath03 :whale: Remove penpot user in gitpod Signed-off-by: madmath03 :whale: Brew install redis Signed-off-by: madmath03 :wrench: Init DB and penpot user Signed-off-by: madmath03 :whale: Switch user for installs Signed-off-by: madmath03 :wrench: Improve startup and DB init Signed-off-by: madmath03 :wrench: Configure gitpod tasks Signed-off-by: madmath03 :wrench: Configure gitpod ports Signed-off-by: madmath03 :wrench: Setup for mailhog Signed-off-by: madmath03 :bug: Use perms to install mailhog :bug: Install mailhog before workspace creation Signed-off-by: mathieu.brunot :wrench: Manage signed commits Signed-off-by: madmath03 :wrench: Configure tasks to wait on ports :wrench: Improve Gitpod config Signed-off-by: madmath03 :arrow_up: Upgrade deps in gitpod Signed-off-by: madmath03 :art: Use absolute path for cd Signed-off-by: madmath03 :wrench: Add nginx conf Signed-off-by: madmath03 :wrench: Fix nginx config for gitpod Signed-off-by: madmath03 :wrench: Ensure nginx listens all incoming :art: Change layers order Signed-off-by: madmath03 :art: Change layers order Signed-off-by: madmath03 :wrench: Set Nginx logs permissions Signed-off-by: madmath03 :bug: Use sudo to create nginx logs Signed-off-by: madmath03 --- .gitpod.yml | 84 +++++++++++++++ README.md | 1 + docker/gitpod/Dockerfile | 103 ++++++++++++++++++ docker/gitpod/files/nginx.conf | 136 ++++++++++++++++++++++++ docker/gitpod/files/postgresql_init.sql | 3 + 5 files changed, 327 insertions(+) create mode 100644 .gitpod.yml create mode 100644 docker/gitpod/Dockerfile create mode 100644 docker/gitpod/files/nginx.conf create mode 100644 docker/gitpod/files/postgresql_init.sql diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 000000000..c513062fa --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,84 @@ +image: + file: docker/gitpod/Dockerfile + +ports: + # nginx + - port: 3449 + onOpen: open-preview + # frontend nREPL + - port: 3447 + onOpen: ignore + visibility: private + # frontend shadow server + - port: 3448 + onOpen: notify + visibility: private + - port: 6060 + - port: 9090 + # exporter shadow server + - port: 9630 + onOpen: notify + visibility: private + # exporter http server + - port: 6061 + onOpen: ignore + # mailhog web interface + - port: 8025 + onOpen: notify + # mailhog postfix + - port: 1025 + onOpen: ignore + # postgres + - port: 5432 + onOpen: ignore + # redis + - port: 6379 + onOpen: ignore + # openldap + - port: 389 + onOpen: ignore + +tasks: + # https://github.com/gitpod-io/gitpod/issues/666#issuecomment-534347856 + - before: > + [[ ! -z ${GNUGPG} ]] && + cd ~ && + rm -rf .gnupg && + echo ${GNUGPG} | base64 -d | tar --no-same-owner -xzvf - + name: signed terminal + init: > + [[ ! -z ${GNUGPG_KEY} ]] && + git config --global commit.gpgsign true && + git config --global user.signingkey ${GNUGPG_KEY} + command: cd $GITPOD_REPO_ROOT + + - init: yarn --cwd $GITPOD_REPO_ROOT/frontend/ install + name: frontend shadow watch + command: cd $GITPOD_REPO_ROOT/frontend/ && npx -y shadow-cljs watch main + + - init: yarn --cwd $GITPOD_REPO_ROOT/exporter/ install + name: exporter shadow watch + command: gp await-port 3448 && cd $GITPOD_REPO_ROOT/exporter/ && npx -y shadow-cljs watch main + + - name: exporter web server + openMode: split-right + command: gp await-port 9630 && cd $GITPOD_REPO_ROOT/exporter/ && ./scripts/wait-and-start.sh + + - init: gp await-port 5432 && psql -f $GITPOD_REPO_ROOT/docker/gitpod/files/postgresql_init.sql + name: backend + command: cd $GITPOD_REPO_ROOT/backend/ && ./scripts/start-dev + + - name: gulp + command: gp await-port 3448 && cd $GITPOD_REPO_ROOT/frontend/ && npx -y gulp --theme=${PENPOT_THEME} watch + + - name: redis + command: redis-server + + - before: go get github.com/mailhog/MailHog + name: mailhog + command: MailHog + + - name: Nginx + command: > + nginx && + multitail /var/log/nginx/access.log -I /var/log/nginx/error.log diff --git a/README.md b/README.md index b508bac45..5bc569307 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ [![License: MPL-2.0][uri_license_image]][uri_license] [![Gitter](https://badges.gitter.im/sereno-xyz/community.svg)](https://gitter.im/penpot/community) [![Managed with Taiga.io](https://img.shields.io/badge/managed%20with-TAIGA.io-709f14.svg)](https://tree.taiga.io/project/penpot/ "Managed with Taiga.io") +[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/penpot/penpot) # PENPOT # diff --git a/docker/gitpod/Dockerfile b/docker/gitpod/Dockerfile new file mode 100644 index 000000000..ea3a0b972 --- /dev/null +++ b/docker/gitpod/Dockerfile @@ -0,0 +1,103 @@ +FROM gitpod/workspace-postgres + +# Install custom tools, runtimes, etc. +# For example "bastet", a command-line tetris clone: +# RUN brew install bastet +# +# More information: https://www.gitpod.io/docs/config-docker/ + +RUN set -ex; \ + brew install redis; \ + brew install imagemagick; \ + brew install mailhog; \ + brew install openldap; \ + sudo mkdir -p /var/log/nginx; \ + sudo chown gitpod:gitpod /var/log/nginx + +COPY docker/gitpod/files/nginx.conf /etc/nginx/nginx.conf + +USER root + +ENV CLOJURE_VERSION=1.10.3.814 \ + CLJKONDO_VERSION=2021.03.03 \ + LANG=en_US.UTF-8 \ + LC_ALL=en_US.UTF-8 + +RUN set -ex; \ + useradd -m -g users -s /bin/bash penpot; \ + passwd penpot -d; \ + echo "penpot ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers + +RUN set -ex; \ + apt-get -qq update; \ + apt-get -qqy install \ + gconf-service \ + libasound2 \ + libatk1.0-0 \ + libatk-bridge2.0-0 \ + libcairo2 \ + libcups2 \ + libdbus-1-3 \ + libexpat1 \ + libfontconfig1 \ + libgcc1 \ + libgconf-2-4 \ + libgdk-pixbuf2.0-0 \ + libglib2.0-0 \ + libgtk-3-0 \ + libnspr4 \ + libpango-1.0-0 \ + libpangocairo-1.0-0 \ + libx11-6 \ + libx11-xcb1 \ + libxcb1 \ + libxcomposite1 \ + libxcursor1 \ + libxdamage1 \ + libxext6 \ + libxfixes3 \ + libxi6 \ + libxrandr2 \ + libxrender1 \ + libxss1 \ + libxtst6 \ + fonts-liberation \ + libappindicator1 \ + libnss3 \ + libgbm1 \ + ; \ + rm -rf /var/lib/apt/lists/*; + +RUN set -ex; \ + wget "https://download.clojure.org/install/linux-install-$CLOJURE_VERSION.sh"; \ + chmod +x "linux-install-$CLOJURE_VERSION.sh"; \ + "./linux-install-$CLOJURE_VERSION.sh"; \ + rm -rf "linux-install-$CLOJURE_VERSION.sh" + +RUN set -ex; \ + cd /tmp; \ + wget "https://github.com/borkdude/clj-kondo/releases/download/v${CLJKONDO_VERSION}/clj-kondo-${CLJKONDO_VERSION}-linux-amd64.zip"; \ + unzip "clj-kondo-${CLJKONDO_VERSION}-linux-amd64.zip"; \ + sudo mv clj-kondo /usr/local/bin/; \ + rm "clj-kondo-${CLJKONDO_VERSION}-linux-amd64.zip"; + +USER gitpod + +ENV PENPOT_SMTP_ENABLED=true \ + PENPOT_SMTP_HOST=localhost \ + PENPOT_SMTP_PORT=1025 \ + PENPOT_SMTP_USER= \ + PENPOT_SMTP_PASSWORD= \ + PENPOT_SMTP_SSL=false \ + PENPOT_SMTP_TLS=false \ + PENPOT_SMTP_DEFAULT_REPLY_TO=no-reply@example.com \ + PENPOT_SMTP_DEFAULT_FROM=no-reply@example.com \ + PENPOT_SMTP_ENABLED=true \ + PENPOT_SMTP_HOST=localhost \ + PENPOT_SMTP_PORT=1025 \ + PENPOT_SMTP_USER= \ + PENPOT_SMTP_PASSWORD= \ + PENPOT_SMTP_SSL=false \ + PENPOT_SMTP_TLS=false + +# TODO Retrieve OpenLDAP from rroemhild/docker-test-openldap diff --git a/docker/gitpod/files/nginx.conf b/docker/gitpod/files/nginx.conf new file mode 100644 index 000000000..80c5d5b43 --- /dev/null +++ b/docker/gitpod/files/nginx.conf @@ -0,0 +1,136 @@ +# This Nginx config file is optional. +# If you don't have this file, the Nginx config from the workspace-full docker image will be taken. + +worker_processes auto; +pid /var/run/nginx/nginx.pid; +include /etc/nginx/modules-enabled/*.conf; + +env GITPOD_REPO_ROOT; + +events { + worker_connections 768; + # multi_accept on; +} + +http { + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + # server_tokens off; + + # server_names_hash_bucket_size 64; + # server_name_in_redirect off; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + gzip on; + + gzip_vary on; + gzip_proxied any; + gzip_comp_level 3; + gzip_buffers 16 8k; + gzip_http_version 1.1; + + gzip_types text/plain text/css text/javascript application/javascript application/json application/transit+json; + + map $http_upgrade $connection_upgrade { + default upgrade; + '' close; + } + + # include /etc/nginx/sites-enabled/*; + + server { + set_by_lua $gitpod_repo_root 'return os.getenv("GITPOD_REPO_ROOT")'; + + listen 0.0.0.0:3449 default_server; + server_name _; + + client_max_body_size 5M; + charset utf-8; + + proxy_http_version 1.1; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Scheme $scheme; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + resolver 8.8.8.8; + + etag off; + + root $gitpod_repo_root/frontend/resources/public; + + location @handle_redirect { + set $redirect_uri "$upstream_http_location"; + set $redirect_host "$upstream_http_x_host"; + set $redirect_cache_control "$upstream_http_cache_control"; + + proxy_buffering off; + + proxy_set_header Host "$redirect_host"; + proxy_hide_header etag; + proxy_hide_header x-amz-id-2; + proxy_hide_header x-amz-request-id; + proxy_hide_header x-amz-meta-server-side-encryption; + proxy_hide_header x-amz-server-side-encryption; + proxy_pass $redirect_uri; + + add_header x-internal-redirect "$redirect_uri"; + add_header x-cache-control "$redirect_cache_control"; + add_header cache-control "$redirect_cache_control"; + } + + location /assets { + proxy_pass http://127.0.0.1:6060/assets; + recursive_error_pages on; + proxy_intercept_errors on; + error_page 301 302 307 = @handle_redirect; + } + + location /internal/assets { + internal; + alias $gitpod_repo_root/backend/resources/public/assets; + add_header x-internal-redirect "$upstream_http_x_accel_redirect"; + } + + location /api { + proxy_pass http://127.0.0.1:6060/api; + } + + location /webhooks { + proxy_pass http://127.0.0.1:6060/webhooks; + } + + location /dbg { + proxy_pass http://127.0.0.1:6060/dbg; + } + + location /export { + proxy_pass http://127.0.0.1:6061; + } + + location /playground { + alias $gitpod_repo_root/experiments/; + add_header Cache-Control "no-cache, max-age=0"; + autoindex on; + } + + location /ws/notifications { + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_pass http://127.0.0.1:6060/ws/notifications; + } + + location / { + add_header Cache-Control "no-cache, max-age=0"; + } + } +} diff --git a/docker/gitpod/files/postgresql_init.sql b/docker/gitpod/files/postgresql_init.sql new file mode 100644 index 000000000..1766a643d --- /dev/null +++ b/docker/gitpod/files/postgresql_init.sql @@ -0,0 +1,3 @@ +CREATE DATABASE penpot; +CREATE USER penpot PASSWORD 'penpot'; +ALTER ROLE penpot SUPERUSER;