18.4.0 released Sep 25, 2023
Example: docker

The following is a bash script that will create a base Vely image as well as a base image for a Vely application, and setup Apache server and MariaDB database. To run this example, you must have Docker, Apache and MariaDB installed on Ubuntu 20 and up or Red Hat 9 or up. You can use docker or podman (substitute podman for docker).

To run this example on Ubuntu:
tar xvf /usr/share/vely/examples/velydocker.tar.gz
cd velydocker
export DBROOTPWD="<mariadb root database pwd>"
export VV_APACHE_CONFIG="/etc/apache2/apache2.conf"
export VV_APACHE_SERVICE="apache2"

DBROOTPWD environment variable should have a MariaDB root database password (or empty if passwordless). VV_APACHE_CONFIG should be the location of Apache configuration file, and VV_APACHE_SERVICE the name of Apache service. You must have sudo privilege to run this example. The settings above are for Ubuntu/Debian, but you can change them for other distros.

The script will create a container with your application installed. You can remove the application source code from the container in "runit" script in order to distribute only the application binaries. You can then run this container on any machine.

Note that Vely demo application source code being containerized is in "docker" directory. You can replace it with your own source code; see application-setup on building application with Vely.

Once the image is built and container started, use the following link(s) to run it, or if you can't, use curl to see the demo application response (the demo is example-stock):
#Add stock ticker 'XYZ' with stock price 450

#Display list of stock tickers

File Dockerfile:
# Create base vely image. Install Vely on top of Ubuntu 20.04
FROM ubuntu:20.04
ENV TZ=America/Phoenix
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt update
RUN apt install -y apt-transport-https ca-certificates wget sudo
RUN wget  -qO - https://vely.dev//pkg/OPENPGP|sudo tee /usr/share/keyrings/vely.asc >/dev/null
ARG arch
RUN sudo bash -c "echo 'deb [signed-by=/usr/share/keyrings/vely.asc] https://vely.dev//pkg/ubuntu_20_$arch/latest ubuntu_20_$arch vely' >/etc/apt/sources.list.d/vely.list"
RUN sudo apt update
RUN sudo apt install -y vely

File velyapp.dockerfile:
# Create image that will be used to compile and link an application. Source code is copied from host,
# application is setup, and the source code is deleted (remove this step if you want to ship the source code).
# After that the image is ready to run in a container. Here, the application name is "velydemo"; change it to
# fit your application. The port used in 2300, you can change that as well.
# Customize the ENTRYPOINT command to fit your runtime.
FROM vely
# create vely user and give it limited sudo powers
RUN useradd -ms /bin/bash vely && echo "vely:vely" | chpasswd
RUN echo "vely ALL=(ALL) NOPASSWD: /usr/bin/vf" >> /etc/sudoers
# default user
USER vely
# default working dir
WORKDIR /home/vely
# copy over source code and make app
COPY ./docker/* /home/vely/
# this is to run app with docker run
ENTRYPOINT [ "./runit" ]

File runvelydocker:

# Vely Docker example. 

# if you want to rebuild all from scratch, switch CACHE to the commented option
# that is useful when installing new Vely version in the base image
# CACHE="--no-cache"

set -eE -o functrace
trap 'echo "Error: status $?, $(caller), line ${LINENO}"' ERR

# Build vely base image
sudo docker build --build-arg arch=$(uname -m) $CACHE -t vely .

# Create persistent named volume for /var/lib/vv in the container
sudo docker volume create velyhome

# Stop current container(s) and remove current images
sudo docker stop velyapp || true
sudo docker rmi --force velyapp || true

# Build a container for your application
sudo docker build $CACHE -t velyapp -f velyapp.dockerfile .

# Add ProxyPass to Apache configuration on the host to be able to access the application
# Web server is on the host for simplicity in this example, but it can be in its own container
sudo sed -i "/^ProxyPass \"\/velydemo\" .*$/d" $VV_APACHE_CONFIG
echo 'ProxyPass "/velydemo" fcgi://' | sudo tee -a $VV_APACHE_CONFIG >/dev/null
sudo a2enmod proxy || true
sudo a2enmod proxy_fcgi || true
sudo service $VV_APACHE_SERVICE restart

# Create a MariaDB database on the host, setup the user and create database objects (a table in this case).
# Database is on the host for simplicity in this example, but it can be in its own container
MKDB=$(echo "create database if not exists velydb; 
create user if not exists velyuser identified by 'pwd';
grant create,alter,drop,select,insert,delete,update on velydb.* to velyuser;
use velydb;
source docker/setup.sql;")

# Execute database setup. 
if [ "$DBROOTPWD" == "" ]; then
    echo $MKDB | sudo mysql
    echo $MKDB | sudo mysql -u root -p$DBROOTPWD

mkdir -p $HOME/libvv
# Now that Vely application container is setup, web server and database setup as well, run it in a container.
# Note that "host" network interface is used for simplicity.
sudo docker run --name velyapp -d -v velyhome:/var/lib/vv  --network="host" --rm velyapp

exit 0

File runit:
# Create Vely application and run it in foreground for docker
# demout has a log of execution
sudo vf -i -u $(whoami) velydemo
vv -c
vv -q --db=mariadb:db -s
vv -c
vf -f -w3 -p2300 velydemo > demout

See also
See all

You are free to copy, redistribute and adapt this web page (even commercially), as long as you give credit and provide a link back to this page (dofollow) - see full license at CC-BY-4.0. Copyright (c) 2019-2023 Dasoftver LLC. Vely and elephant logo are trademarks of Dasoftver LLC. The software and information on this web site are provided "AS IS" and without any warranties or guarantees of any kind.