Skip to content

Instantly share code, notes, and snippets.

@sesopenko
Last active May 8, 2021 22:20
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sesopenko/2f392c6fef73f16a3660ec74aef0bff1 to your computer and use it in GitHub Desktop.
Save sesopenko/2f392c6fef73f16a3660ec74aef0bff1 to your computer and use it in GitHub Desktop.
Automated, complete dev environment setup for building Phoenix web apps in Ubuntu 20.10 with Docker and MariaDB

README

Installs the following:

  • nodejs 14 from nodesources.com
  • elixir 1.10 from ubuntu repos
  • erlang/OTP 22 from ubuntu repos
  • phoenix 1.5.8 cli tool
  • docker 20.10 from docker
  • docker-compose 1.29 from docker
  • mix
  • mariadb 10 from official dockerhub
  • mailhog from official dockerhub

Why did I create this?

I wanted to have consistency between environments when I move back and forth between my laptop and desktop and was tired of forgetting little things or missing steps in a big markdown file I was maintaining.

I format & reinstall my workstation & laptop OS with each distribution upgrade and had to recently replace my laptop under warranty so having a scripted installation of my dev environment was overdue. I've experienced the pain, dealt with it, & felt it'd be helpful for others to avoid the pain I was going through by sharing the environment setup makefile I created.

Requirements:

  • Ubuntu 20.10 (tested on desktop, laptop, then replacement laptop)
  • make

Caveat Emptor

This is using remotely downloaded, 3rd party scripts from nodesources.com and using 3rd party PGP repos. You're responsible for the security of your app and infrastructure. Read over the Makefile before you type in your sudo password and if you're not feeling comfortable, don't do it. I'm using this for my own dev environment but no warranty or guarantee is provided or implied.

These are reputable 3rd parties but with great power comes great responsibility. Do your homework if you're using this in a business context, for sure.

Rough Instructions:

These were copy/pasted from a private repo. I'm confident in the make setup-dev-env step but make start depends on you sorting out how to install the phoenix app in an existing folder. Rough steps are outlined here.

  1. Create folder, copy Makefile and docker-compose.yml files over
  2. sudo apt-get install build-essential (for make, and some packages need to build binaries)
  3. make setup-dev-env (will install elixir, node, npm, erlang, docker, docker-compose, mix, phoenix)
  4. generate phoenix project in project folder with --database mysql flag
  5. make start (will install backend/frontend deps, deploy docker stack, create db, run migrations, and start phoenix app with live-reload)
  6. Go to http://localhost:4000 to see your phoenix webapp
  7. Go to http://localhost:8080 for phpmyadmin db administration. user: root, pass: password
  8. Go to http://localhost:8025 for mailhog web ui. Can test & monitor e-mails sent by your app.

Sources:

version: "3.9"
services:
db:
image: mariadb
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
ports:
- 3306:3306
volumes:
- mariadb:/var/lib/mysql
networks:
- streamline
phpmyadmin:
image: phpmyadmin
restart: always
ports:
- 8080:80
environment:
- PMA_ARBITRARY=1
- PMA_HOST=db
networks:
- streamline
mailhog:
image: mailhog/mailhog
restart: always
ports:
- 1025:1025
- 8025:8025
volumes:
mariadb:
networks:
streamline:
LSB_RELEASE := $(shell lsb_release -cs)
WHOAMI := $(shell whoami)
SYSTEM := $(shell uname -s)
ARCH := $(shell uname -m)
NODE_VERSION := 14
PHOENIX_VERSION := 1.5.8
install-nodejs:
cd /tmp/
curl -sL https://deb.nodesource.com/setup_$(NODE_VERSION).x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt-get install nodejs -y
node --version
npm --version
install-mariadb:
sudo apt-get install mariadb-client -y
install-erlang:
sudo apt-get install erlang -y
install-elixir: install-erlang
sudo apt-get install elixir -y
install-hex: install-elixir
elixir --version
mix local.hex --force
install-live-reloading:
sudo apt-get install inotify-tools -y
install-phoenix: install-elixir install-hex install-nodejs install-mariadb install-live-reloading
mix archive.install hex phx_new $(PHOENIX_VERSION) --force
phpmyadmin:
sensible-browser http://localhost:8080
@echo "The db is 'db', user is 'root', and password is 'password'"
mailhog:
sensible-browser http://localhost:8025
@echo "Opened mailhog in default browser"
unit:
mix test
docker-uninstall:
sudo rm -f /etc/apt/sources.list.d/docker.list
-sudo apt-get remove docker-ce docker docker-engine docker.io containerd runc -y
-sudo apt-get purge docker docker-ce docker-ce-cli containerd.io -y
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
docker-setup-repo:
echo "For more information, see https://docs.docker.com/engine/install/ubuntu/"
sudo apt-get update
@echo "Setting up the repository"
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release \
-y
@echo "Adding docker's official GPG key"
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --batch --yes --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
@echo "Setting up the stable repository"
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(LSB_RELEASE) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
docker-install: docker-setup-repo
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io -y
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
sudo usermod -aG docker $(WHOAMI)
newgrp docker
docker --version
@echo "You now have to log out and back in to use docker."
install-docker-compose: docker-install
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(SYSTEM)-$(ARCH)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
setup-dev-env: docker-install install-phoenix
backend-deps:
mix deps.get
frontend-deps:
cd assets && npm install
deps: frontend-deps backend-deps
docker-up:
docker-compose up -d
ecto-create: docker-up
mix ecto.create
ecto-migrate: ecto-create
mix ecto.migrate
start: ecto-migrate deps
mix phx.server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment