blob: 4c389438874dbe0ad838bd9a06b3ea85efa769bf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# Cryptoportfolio app
Back and front end for cryptoportfolio project.
Server binaries and webapp files are shipped to Github. No need to install dev dependencies to deploy it. All you need is [ansible](http://docs.ansible.com/ansible/latest/intro_installation.html#installing-the-control-machine)
- [Deploy](#deploy) : deploy server binaries and webapp archive to a server with ansible
- [Server](#server) : server written in golang
- [Webapp](#webapp) : JS (React)
- [Release](#release) : release server binaries and webapp archive to github with ansible.
Dir tree
```
|- api/*.go api endpoints
|- db/*.go database models
|- cmd/
| |--- app/
| |-- Makefile
| |-- conf.toml server configuration file (dev)
| |-- main.go server entry point
| |--- ansible/
| |-- ansible.cfg
| |-- hosts
| |-- requirements.yml
| |-- conf.toml.j2 server configuration file (prod)
| |-- cryptoportfolio-app.j2 server systemd file
| |-- vars.yml playbook variables (vault)
| |-- release.yml release playbook
| |-- deploy.yml deploy playbook
| |--- web/
| |-- env/ app environments
| |-- dev.env
| |-- prod.env
| |-- js/ js source code
| |-- static/ index.html and style.css
```
## Server
#### Install
##### Golang installation (if needed)
1. Download right package at [https://golang.org/dl](https://golang.org/dl)
2. Install it
```
tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
export PATH=$PATH:/usr/local/go/bin
```
#### Fetch dependencies
Simply run at the root of project :
```
make install
```
#### Run locally
You need postgres running on `localhost:5432` and the following setup:
```
CREATE USER cryptoportfolio;
ALTER USER cryptoportfolio WITH ENCRYPTED PASSWORD 'cryptoporfolio-dev';
ALTER ROLE cryptoportfolio WITH CREATEDB ;
CREATE DATABASE cryptoportfolio OWNER cryptoportfolio;
```
Then run the app in cmd/app:
```
cd cmd/app
make run
```
## Webapp
#### Install
You will need `npm`, `node` and `yarn`, then:
```
cd cmd/web
make install
```
#### Build local webapp
```
make static ENV=dev
```
Files are now ready to be served by server.
## Ansible install requirements
```
cd cmd/ansible
ansible-galaxy install -r requirements.yml
```
## Releasing
To release, you need to have all dev environments setup for server and webapp. The token used to push to Github is in cmd/ansible/vars.yml. You need a password to decrypt this file. Ask me. You need to store this password in a file such as `~/.vault_cryptoportfolio_pass.txt`
You can then run the release.yml playbook, don't forget to provide a the release version :
```
cd cmd/ansible
ansible-playbook release.yml --extra-vars "version=X.X.X" --vault-password-file=~/.vault_cryptoportfolio_pass.txt
```
## Deploy
change `hosts` file :
```
[jloup-home]
jlj.am
[jloup-home:vars]
ansible_port=21
ansible_user=ansible-deploy # This user will be used to carry out operation on remote machine
# To make it work, this user should not be prompted for password when sudo
# else you need to pass --ask-sudo-pass when running playbook
app_user=jloup # user that will run the app service
app_domain=jlj.am
postgres_database=cryptoportfolio
postgres_user=cryptoportfolio
postgres_password=cryptoportfolio-dev
linux_arch=386 # your machine arch. should be one if [386, amd64]
```
```
cd cmd/ansible
ansible-playbook deploy.yml --extra-vars "version=X.X.X" --vault-password-file=~/.vault_cryptoportfolio_pass.txt
```
|