-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: upload current git file-tree into vm So we can actually use this to test the current deployment refactor: set up `pnpm` Motivation ---------- `pnpm` itself has a number of advantages, two are very relevant for our repository: * De-duplication of node modules * Run commands across packages This will also setup `dotenvx` to read .env files (for unique port numbers). It will also make local development with `docker compose` obsolete for our nodejs projects. How to test ----------- 1. `pnpm install` 2. `pnpm run -r dev` commits: * fix unique ports and environments * fix: extraneous import * remove obsolete `package-lock.json` * run `pnpm install` * run `corepack use pnpm@latest`
- Loading branch information
1 parent
e90affd
commit 5aac99e
Showing
9 changed files
with
145 additions
and
67 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
packer-output/ | ||
archive/**/* | ||
!archive/.gitkeep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Infrastructure | ||
|
||
This folder contains our infrastructure as code. | ||
|
||
The [benefits](https://www.redhat.com/en/topics/automation/what-is-infrastructure-as-code-iac#benefits-of-iac) of this paradigm are: | ||
- Cost reduction | ||
- Increase in speed of deployments | ||
- Reduce errors | ||
- Improve infrastructure consistency | ||
- Eliminate configuration drift | ||
|
||
## Local setup | ||
|
||
The following will set up virtual machines locally so you can test out if a change breaks the deployment. | ||
|
||
1. Install [packer](https://www.packer.io/) on your machine | ||
|
||
1. `cd infrastructure/` | ||
|
||
1. `packer init ./vagrant.pkr.hcl` | ||
|
||
### (Re)build Vagrant box | ||
|
||
1. Install [Vagrant](https://www.vagrantup.com/) and [VirtualBox](https://www.virtualbox.org/) on your machine | ||
|
||
1. `packer build --force --on-error=ask ./vagrant.pkr.hcl` | ||
|
||
1. `cd vagrant && vagrant up` | ||
|
||
1. Following services are running: | ||
- <http://localhost:8000/> | ||
- <http://localhost:8000/api> | ||
- <http://localhost:8000/docs> | ||
- <http://localhost:8080> | ||
- <http://localhost:8082> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euxo pipefail | ||
|
||
apk update | ||
apk upgrade | ||
apk add nginx openrc nodejs npm git mysql mysql-client | ||
|
||
npm install -g pnpm pm2 | ||
pm2 startup | ||
|
||
rc-update add pm2 boot | ||
rc-update add nginx boot | ||
service nginx start | ||
|
||
service mariadb setup | ||
rc-update add mariadb boot | ||
sed -e '/skip-networking/ s/^#*/#/' -i /etc/my.cnf.d/mariadb-server.cnf | ||
service mariadb start | ||
|
||
|
||
PROJECT_ROOT=/var/www/localhost/htdocs/dreammall.earth | ||
|
||
mkdir -p /etc/nginx/http.d | ||
cp -f $PROJECT_ROOT/deployment/nginx/default.conf /etc/nginx/http.d/default.conf | ||
cp $PROJECT_ROOT/deployment/nginx/frontend.conf /etc/nginx/http.d/frontend.conf | ||
cp $PROJECT_ROOT/deployment/nginx/admin.conf /etc/nginx/http.d/admin.conf | ||
|
||
mysql -e "CREATE USER 'dreammall'@'localhost' IDENTIFIED BY 'SECRET'; GRANT ALL PRIVILEGES ON * . * TO 'dreammall'@'localhost'; FLUSH PRIVILEGES;" | ||
|
||
cp $PROJECT_ROOT/backend/.env.dist $PROJECT_ROOT/backend/.env | ||
cp $PROJECT_ROOT/presenter/.env.dist $PROJECT_ROOT/presenter/.env | ||
cp $PROJECT_ROOT/frontend/.env.dist $PROJECT_ROOT/frontend/.env | ||
cp $PROJECT_ROOT/admin/.env.dist $PROJECT_ROOT/admin/.env | ||
|
||
$PROJECT_ROOT/deployment/deploy.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
packer { | ||
required_plugins { | ||
vagrant = { | ||
version = "~> 1" | ||
source = "github.com/hashicorp/vagrant" | ||
} | ||
} | ||
} | ||
|
||
source "vagrant" "dreammall" { | ||
communicator = "ssh" | ||
source_path = "generic/alpine319" | ||
provider = "virtualbox" | ||
add_force = true | ||
|
||
output_dir = "packer-output" | ||
} | ||
|
||
build { | ||
sources = ["sources.vagrant.dreammall"] | ||
|
||
|
||
provisioner "shell-local" { | ||
inline = [ | ||
"rm -rf archive", | ||
"git clone ../ archive", | ||
"cd archive", | ||
"git remote set-url origin https://github.com/dreammall-earth/dreammall.earth.git", # only necessary because of the `git pull -ff` in `deploy.sh` | ||
"git checkout master", | ||
"git pull -ff", | ||
"touch .gitkeep", | ||
] | ||
} | ||
|
||
provisioner "file" { | ||
source = "archive" | ||
destination = "/tmp" | ||
} | ||
|
||
provisioner "shell" { | ||
execute_command = "echo 'packer' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'" | ||
inline = [ | ||
"mkdir -p /var/www/localhost/htdocs/", | ||
"mv /tmp/archive /var/www/localhost/htdocs/dreammall.earth", | ||
] | ||
} | ||
|
||
provisioner "shell" { | ||
execute_command = "echo 'packer' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'" | ||
script = "./bootstrap.sh" | ||
} | ||
|
||
provisioner "shell-local" { | ||
inline = [ | ||
"rm -rf archive/", | ||
"mkdir -p archive/", | ||
"touch archive/.gitkeep", | ||
] | ||
} | ||
|
||
error-cleanup-provisioner "shell-local" { | ||
inline = [ | ||
"rm -rf archive/", | ||
"mkdir -p archive/", | ||
"touch archive/.gitkeep", | ||
] | ||
} | ||
} | ||
|
File renamed without changes.
9 changes: 2 additions & 7 deletions
9
deployment/local-testing/Vagrantfile → infrastructure/vagrant/Vagrantfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters