# schema-webstack LXD container install guide # C. Campbell # 08.07.2023 # Summary: install schema-webstack with minimal install steps and requirements for development # Terms: host is syn with your computer, container is the guest LXD container running on your WSL host # storage type chosen for LXD init was btrfs # the host homespace used for container creation was /home/ccampbell, you will need to replace some configurations # with the name of your homespace, this will be detailed below # the term means replace with the name of your actual homespace # Check snap capabilities on your host computer snap info lxd # this should list package information for LXD and the available channels # this will also show if lxd is installed and version # if not you will need to make sure your snap environment is installed and updated # if you are behind the nutramax proxy # set snap config for proxy sudo snap set system proxy.http="http://172.16.0.129:3128" sudo snap set system proxy.https="http://172.16.0.129:3128" # install snap latest/stable ( should be 5.15+ ) sudo snap install lxd --channel=latest/stable # initial configuration of LXD, mostly use the defaults unless something looks wrong # storage type btrfs was used for the image pool, used the default 30Gig pool, you might want more? lxd init # make the NAT prerouting connections needed to map the host to container sudo ufw allow in on lxdbr0 comment 'lxdbr0 for LXD' sudo ufw route allow in on lxdbr0 comment 'lxdbr0 for LXD' sudo ufw route allow out on lxdbr0 comment 'lxdbr0 for LXD' sudo ufw enable # set proxy for lxc commands if needed lxc config set core.proxy_http http://172.16.0.129:3128 lxc config set core.proxy_https http://172.16.0.129:3128 # create directory and git clone the schema-webstack project on your local host # this is the example of how I handle this locally, your setup could be different. mkdir -p ~/node.js/schema-webstack cd ~/node.js/schema-webstack git clone https://github.com/Nutramax/schema-webstack.git . git checkout dev # retrieve, download the schema-webstack container backup to your host, this will be shared in OneDrive # should be along side this install guide # the following is how I handled it, your setup may vary and the file name might be different # make sure to grab the most recent backup file of this naming lxc import ~/lxd_snapshots/schema_webstack_container.08072023.xz schema-webstack-8080 # when the import is completed, check the container info lxc info schema-webstack-8080 # Start the container, to check if it worked lxc start schema-webstack-8080 # shell into the container as the webstack user, see if everything looks correct # if this works you should see a shell for the webstack user # run pm2 status, should see a Directus running lxc exec schema-webstack-8080 -- su - webstack pm2 status # if you do not get shell access as the container webstack user at this point stop and ask for help # now we have to reconfigure the path mapping so that it matches your schema-webstack directory on the host, to what is expected in the container # the source= part is what needs to be changed according to your host # do not change the path= part, that is the expected path in the container lxc config device set schema-webstack-8080 schema_webstack disk source=/node.js/schema-webstack/ path=/home/webstack/schema-webstack/ # now make sure the LXD instance IP matches the original container settings # the original container used IP 10.80.77.38 # to find out run the following: lxc info schema-webstack-8080 # look for the section eth0: IP addresses: inet: # if the IP address is not 10.80.77.38 you will need to remap the ports for directus and nginx # directus map lxc config device set schema-webstack-8080 directus8055 proxy listen=tcp:127.0.0.1:8055 connect=tcp::8055 lxc config device set schema-webstack-8080 http8080 proxy listen=tcp:127.0.0.1:8080 connect=tcp::8080 # now the proxy mappings should be pointing correctly into the container # Try going to directus in the browser http://localhost:8055/admin # if you do not see the directus login, stop and ask for help http://localhost:8080/tests/ # if you do not see a list of tests, stop and ask for help # if you see errors on start similar to this # Error: Failed start validation for device "eth0": MAC address "00:16:3e:ac:91:95" already defined on another NIC # this can happen when snap updates LXD or something has changed in WSL or the linux kernel # run the following lxc config unset schema-webstack-8080 volatile.eth0.hwaddr # now the container will start but it probably means your device IP address has changed # run info on the container now that it has started to see the IP address it picked up lxc info schema-webstack-8080 # if the ip4 inet address did change, we have to reconfigure the proxy device settings so we can access the container network via localhost # run config debug to see the device settings lxc config device list schema-webstack-8080 --debug # in this example the IP changed from 10.80.77.38 to 10.80.77.161 # reset the proxy settings lxc config device remove schema-webstack-8080 directus8055 lxc config device add schema-webstack-8080 directus8055 proxy listen=tcp:127.0.0.1:8055 connect=tcp:10.80.77.161:8055 lxc config device remove schema-webstack-8080 http8080 lxc config device add schema-webstack-8080 http8080 proxy listen=tcp:127.0.0.1:8080 connect=tcp:10.80.77.161:8080 # if you have trouble reaching the proxy localhost settings above from the host browser, make sure ufw is up sudo ufw enable # Creating a new container to seperate dev, stage and production lxc import ~/lxc_containers/schema_webstack.10122023.tar.xz stage-schema-webstack lxc config device list stage-schema-webstack lxc config device remove stage-schema-webstack directus8055 lxc config device remove stage-schema-webstack http8080 lxc config device remove stage-schema-webstack schema_webstack lxc config unset stage-schema-webstack volatile.eth0.hwaddr # do this to get the new internal IP of the container, you need this to set your network mappings ( proxy ) config lxc list lxc config device add stage-schema-webstack schema_webstack disk source=/home/ccampbell/node.js/dev_schema-webstack/ path=/home/webstack/schema-webstack/ lxc config device add stage-schema-webstack directus8056 proxy listen=tcp:127.0.0.1:8056 connect=tcp:10.80.77.20:8055 lxc config device add stage-schema-webstack node9002 proxy listen=tcp:127.0.0.1:9002 connect=tcp:10.80.77.20:9001 # Creating a database instance for stage inside existing container # enter container as root lxc exec dev - su - mysql # these are SQL commands create database denamarin_stage; grant all on denamarin_stage.* to 'developer_user'; show grants for 'webdev'@'localhost'; show grants for 'webdev'@'localhost' using 'developer_user; ## create and restore scripts have been modified to allow for 2 parameters, database name then file name # example to clone an existing directus ./create-snapshot.sh schema_webstack snapshot.dev.12052023_1.sql # Edit the restore file to use the new db: USE denamarin_stage; added to top of backup file ./restore-snapshot.sh denamarin_stage snapshot.dev.12052023_1.sql.gz # cp directus or install it into a new directory, this is the structure that is being built into the new stack container denamarin.com/stage/directus denamarin.com/stage/stack # it was determined that building out an entirely new container for each instance was overkill, a container should # be able to handle the 3 instances of a brand site (dev,stage,live) and splitting it up this way inside the container # should work cp -r directus_latest/* denamarin.com/stage/directus/ # cp the .env file and modifiy it for the new directus instance # for example change the port and the redis key prefix # setup the device proxy for the new stage directus lxc config device add dev directus8155 proxy listen=tcp:127.0.0.1:8155 connect=tcp:10.80.77.161:8155 # setup the device proxy for the stage denamarin node instance lxc config device add dev denamarin_stage proxy listen=tcp:127.0.0.1:9002 connect=tcp:10.80.77.161:9002