refactor: reorganize with some changes the docker images and manage.sh

This commit is contained in:
Andrey Antukh 2019-06-03 16:53:31 +02:00
parent 3b648f5aa5
commit a2c41cf9a7
20 changed files with 321 additions and 198 deletions

View file

@ -1,6 +1,13 @@
FROM ubuntu:xenial
LABEL maintainer="Andrey Antukh <niwi@niwi.nz>"
ARG EXTERNAL_UID=1000
ENV NODE_VERSION=v10.16.0 \
LANG=en_US.UTF-8 \
LC_ALL=C.UTF-8 \
UXBOX_CONFIG_URL="/api"
RUN set -ex; \
apt-get update && \
apt-get install -yq \
@ -20,28 +27,7 @@ RUN set -ex; \
webp \
; \
mkdir -p /etc/resolvconf/resolv.conf.d; \
echo "nameserver 8.8.8.8" > /etc/resolvconf/resolv.conf.d/tail; \
apt-get update -yq; \
apt-get install -yq \
libbz2-dev liblzma-dev zlib1g-dev libfftw3-dev \
libfreetype6-dev libfontconfig1-dev libxt-dev \
libexif-dev libjpeg-dev libpng-dev libtiff-dev \
libwmf-dev libpango1.0-dev librsvg2-bin librsvg2-dev \
libxml2-dev libwebp-dev webp autoconf \
; \
git clone https://github.com/ImageMagick/ImageMagick.git imagemagick && \
cd imagemagick && \
git checkout -f 7.0.8-27 && \
./configure --prefix=/opt/img && \
make -j2 && \
make install && \
cd .. && \
rm -rf ./imagemagick
ENV NODE_VERSION=8.15.0 \
LANG=en_US.UTF-8 \
LC_ALL=C.UTF-8 \
UXBOX_CONFIG_URL="/api"
echo "nameserver 8.8.8.8" > /etc/resolvconf/resolv.conf.d/tail;
RUN set -ex; \
echo "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main" >> /etc/apt/sources.list; \
@ -53,10 +39,10 @@ RUN set -ex; \
sudo \
tmux \
vim \
curl \
;
COPY files/pg_hba.conf /etc/postgresql/9.6/main/pg_hba.conf
# COPY files/postgresql.conf /etc/postgresql/9.5/main/postgresql.conf
COPY files/bashrc /root/.bashrc
COPY files/vimrc /root/.vimrc
@ -72,24 +58,30 @@ EXPOSE 6060
EXPOSE 9090
RUN set -ex; \
useradd -m -g users -s /bin/bash uxbox; \
useradd -m -g users -s /bin/bash -u $EXTERNAL_UID uxbox; \
passwd uxbox -d; \
echo "uxbox ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
RUN set -ex; \
wget https://download.clojure.org/install/linux-install-1.10.0.442.sh; \
chmod +x linux-install-1.10.0.442.sh; \
./linux-install-1.10.0.442.sh; \
rm -rf linux-install-1.10.0.442.sh
USER uxbox
WORKDIR /home/uxbox
COPY files/lein /home/uxbox/.local/bin/lein
RUN set -ex; \
git clone https://github.com/creationix/nvm.git .nvm; \
bash -c "source .nvm/nvm.sh && nvm install $NODE_VERSION"; \
bash -c "source .nvm/nvm.sh && nvm alias default $NODE_VERSION"; \
bash -c "source .nvm/nvm.sh && nvm use default"; \
bash -c "/home/uxbox/.local/bin/lein version"
bash -c "source .nvm/nvm.sh && nvm use default";
COPY files/bashrc /home/uxbox/.bashrc
COPY files/vimrc /home/uxbox/.vimrc
COPY files/start.sh /home/uxbox/.start.sh
COPY files/start.sh /home/uxbox/start-tmux.sh
COPY files/tmux.conf /home/uxbox/.tmux.conf
COPY files/entrypoint.sh /home/uxbox/
CMD /home/uxbox/.start.sh
ENTRYPOINT ["bash", "/home/uxbox/entrypoint.sh"]
CMD ["/home/uxbox/start-tmux.sh"]

View file

@ -0,0 +1,10 @@
#!/usr/bin/env bash
source ~/.bashrc
echo `env`
cd /home/uxbox/uxbox/frontend
npm install || exit 1;
npm run dist
# TODO: WIP

View file

@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -e
echo "UXBOX Docker entrypoint initialization..."
exec "$@"

View file

@ -5,8 +5,7 @@ tmux -2 new-session -d -s uxbox
tmux new-window -t uxbox:1 -n 'figwheel'
tmux select-window -t uxbox:1
tmux send-keys -t uxbox 'cd uxbox/frontend' enter C-l
tmux send-keys -t uxbox "sed -i -e 's/\"uxbox.config.url\" \".*\"/\"uxbox.config.url\" \"${UXBOX_CONFIG_URL}\"/g' figwheel.clj" enter C-l
tmux send-keys -t uxbox 'npm run figwheel' enter
tmux send-keys -t uxbox 'npm run start' enter
tmux new-window -t uxbox:2 -n 'backend'
tmux select-window -t uxbox:2

83
docker/docker-compose.yml Normal file
View file

@ -0,0 +1,83 @@
version: "3"
volumes:
backend_m2:
backend_data:
db_data:
networks:
default:
driver: bridge
ipam:
config:
- subnet: 172.177.57.0/24
services:
uxdb:
image: postgres:latest
container_name: uxdb
restart: always
ports:
- "5432:5432"
environment:
- POSTGRES_INITDB_ARGS="--data-checksums"
- POSTGRES_DB=uxbox
- POSTGRES_USER=uxbox
- POSTGRES_PASSWORD=uxbox_postgres_password
volumes:
- db_data:/var/lib/postgresql/data
# - /etc/localtime:/etc/localtime:ro
# - /etc/timezone:/etc/timezone:ro
uxbackend:
image: uxbox-backend:latest
container_name: uxbackend
restart: always
depends_on:
- uxdb
ports:
- 6060:6060
volumes:
- backend_data:/srv/uxbox/resources/public
- backend_m2:/root/.m2
# - /etc/localtime:/etc/localtime:ro
# - /etc/timezone:/etc/timezone:ro
environment:
# HTTP setup
- UXBOX_HTTP_SERVER_DEBUG=false
- UXBOX_MEDIA_URI="/media/"
- UXBOX_ASSETS_URI="/static/"
# Database setup
- UXBOX_DATABASE_USERNAME="uxbox"
- UXBOX_DATABASE_PASSWORD="uxbox_postgres_password"
- UXBOX_DATABASE_NAME="uxbox"
- UXBOX_DATABASE_SERVER="uxdb"
- UXBOX_DATABASE_PORT=5432
# Mail setup
- UXBOX_EMAIL_REPLY_TO="no-reply@uxbox.io"
- UXBOX_EMAIL_FROM="no-reply@uxbox.io"
# STMP setup
- UXBOX_SMTP_HOST="localhost"
- UXBOX_SMTP_PORT=25
- UXBOX_SMTP_USER="uxbox"
- UXBOX_SMTP_PASSWORD="youshouldoverwritethiswithsomethingelse"
- UXBOX_SMTP_SSL=false
- UXBOX_SMTP_TLS=false
- UXBOX_SMTP_ENABLED=false
# Security setup
- UXBOX_SECRET="foobar"
uxfrontend:
image: uxbox-frontend:latest
container_name: uxfrontend
#hostname: uxbox.io
restart: always
depends_on:
- uxbackend
ports:
- 80:80
volumes:
- backend_data:/srv/uxbox/
# - /etc/localtime:/etc/localtime:ro
# - /etc/timezone:/etc/timezone:ro

View file

@ -0,0 +1,34 @@
FROM openjdk:8-jre
LABEL maintainer="Monogramm Maintainers <opensource at monogramm dot io>"
ENV LANG=en_US.UTF-8 \
LC_ALL=C.UTF-8
RUN set -ex; \
wget https://download.clojure.org/install/linux-install-1.10.0.442.sh; \
chmod +x linux-install-1.10.0.442.sh; \
./linux-install-1.10.0.442.sh; \
rm -rf linux-install-1.10.0.442.sh
RUN set -ex; \
apt-get update -yq && \
apt-get install -yq \
git \
imagemagick \
webp
COPY ./entrypoint.sh /entrypoint.sh
COPY ./dist /srv/uxbox
RUN set -ex; \
chmod 755 /entrypoint.sh; \
mkdir -p /srv/uxbox/resources/media
VOLUME /srv/uxbox/resources/public
WORKDIR /srv/uxbox/
EXPOSE 6060
ENTRYPOINT ["sh", "/entrypoint.sh"]
CMD ["clojure", "-m", "uxbox.main"]

View file

@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -e
echo "Setting up UXBOX Backend..."
exec "$@"

View file

@ -0,0 +1,13 @@
# Once application has been built, prepare production image
FROM nginx:alpine
LABEL maintainer="Monogramm Maintainers <opensource at monogramm dot io>"
ENV LANG=en_US.UTF-8 \
LC_ALL=C.UTF-8
# Copy built app to www root
COPY ./dist /usr/share/nginx/html
# NGINX configurations
COPY ./nginx/conf.d /etc/nginx/conf.d

View file

@ -0,0 +1,40 @@
# Setting up NGNIX
You will need to complete the following tasks to setup your dockerized proxy server:
1. Include/Create SSL keys
2. Alter your backend upstream
3. Confirm your backend's path
## Include/Create SSL Keys
Have your key and csr in the nginx/keys directory as server.key and server.crt. These are copied into the docker image on build and used to serve your website or proxy your services.
### Generate your own self signed certificate
```bash
openssl req \
-newkey rsa:2048 -nodes -keyout nginx/keys/server.key \
-x509 -out nginx/keys/server.crt
```
This command from your project root will create the keys needed to start docker with self signed certificates. Note that if you are going to deploy this site for production you will want to replace these and rebuild your image with valid (purchased) SSL certificates. All the fields are optional. Do not set any challenge passwords.
If you want validated certificates but are not looking to purchase them; then checkout [Let's Encrypt](https://letsencrypt.org) which is a free SSL certification service.
## Alter your backend upstream
The upstream is a block used to load balance different destinations important to your proxy. In this example the upstream is used to proxy requests to your backend without worrying about XSS configurations.
We have preloaded some examples of what this looks like in the `nginx/conf.d/default.conf` file. You can certainly only specify one server in the block if that is your only server.
## Confirm your backend's path
Assuming your website uses a backend collection of APIs, you can setup your nginx service to reverse proxy to them avoiding any XSS configuration needs. The provided default.conf includes a `/api/` location block to serve as an example. You can replace api in `/api/` with any path you want to have forwarded to your backend.
There is only one setting you need to adjust in this block and that is the `proxy_cookie_domain`. Assuming you have a production domain you would change `my.uxbox.com` to be your domain. If you do not have a production domain it is safe to leave this as is or delete.
## Extending the configuration
You can include more servers or configuration settings by adding any named file in `nginx/conf.d`. These files are automatically consumed by nginx on startup.
[Visit NGINX's beginnner's guide](http://nginx.org/en/docs/beginners_guide.html) for additional help.

View file

@ -0,0 +1,41 @@
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
# Frontend
location / {
root /usr/share/nginx/html/;
try_files $uri /index.html;
gzip on;
gzip_types text/css text/javascript application/x-javascript application/javascript application/json;
add_header Cache-Control "max-age=15552000" always;
}
location /view {
alias /usr/share/nginx/html/view;
}
location /media {
alias /srv/uxbox/media;
}
location /static {
alias /srv/uxbox/static;
}
# Backend
location /api/ {
proxy_pass http://uxbackend:6060/api/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

View file

@ -0,0 +1,3 @@
log_format gzip '[$time_local] ' '"$request" $status $bytes_sent';
access_log /dev/stdout;
charset utf-8;