This repository has been archived on 2023-07-09. You can view files and clone it, but cannot push or open issues or pull requests.
sudoscientist-go-backend/README.md

91 lines
3.5 KiB
Markdown
Raw Normal View History

2019-02-03 05:56:29 +00:00
# sudoscientist
2019-04-14 03:38:51 +00:00
## sudoscientist blog
2019-02-03 06:57:08 +00:00
2019-04-14 03:38:51 +00:00
### Setup
Install steps are for Debian 9 (stretch)
1. Install docker-ce
```
# stolen from https://docs.docker.com/install/linux/docker-ce/debian/
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
# verify the key's fingerprint
# ----------
sudo apt-key fingerprint 0EBFCD88
pub 4096R/0EBFCD88 2017-02-22
Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
Docker Release (CE deb) <docker@docker.com>
sub 4096R/F273FCD8 2017-02-22
# ----------
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
```
2. Install golang 1.11
```
# stretch doesn't have the latest golang so we install backports
sudo add-apt-repository "deb http://deb.debian.org/debian stretch-backports main"
sudo apt-get update
sudo apt-get -t stretch-backports install golang
# set the gopath manually for the rest of the setup
export GOPATH=${HOME}/go
```
2020-01-18 19:58:55 +00:00
3. Install migrate
```
# this assumes you have ${GOPATH}/bin in your ${PATH}
go get -u -d github.com/mattes/migrate/cli github.com/lib/pq
go build -tags 'postgres' -o ${GOPATH}/bin/migrate github.com/mattes/migrate/cli
```
4. Clone repo and configure the settings
2019-04-14 03:38:51 +00:00
```
mkdir -p ${GOPATH}/src/git.minhas.io/asara
cd ${GOPATH}/src/git.minhas.io/asara
2019-10-04 03:36:54 +00:00
git clone https://git.minhas.io/asara/sudoscientist-go-backend
2019-04-14 03:38:51 +00:00
# iterate through the environment files in the settings directory and set them appropriately
# make sure the extension is .env (db.env, secrets.env, website.env... etc.)
```
2020-01-18 19:58:55 +00:00
5. Configure docker postgres for testing
2019-04-14 03:38:51 +00:00
```
# make sure your user is in the docker group
sudo usermod -aG docker $(whoami)
# make sure you have some postgres client installed
sudo apt-get install postgres-client
docker pull postgres
docker run --name sudosci-db -e POSTGRES_PASWORD=${DB_ADMIN_PW} -d postgres # please set the db admin pw manually
# Initalize the postgres DB
cd ${GOPATH}/src/git.minhas.io/asara/sudoscientist
for i in settings/*; do source $i; done
export DB_HOST=$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" sudosci-db)
psql -d postgres -U postgres -h ${DB_HOST} << EOF
CREATE DATABASE ${DB_NAME};
CREATE USER ${DB_USER} WITH ENCRYPTED PASSWORD '${DB_PW}';
GRANT ALL PRIVILEGES ON DATABASE ${DB_NAME} TO ${DB_USER};
2020-01-18 19:58:55 +00:00
ALTER DATABASE ${DB_NAME} OWNER TO ${DB_USER};
2019-04-14 03:38:51 +00:00
EOF
```
2020-01-18 19:58:55 +00:00
6. Run the application!
2020-01-19 02:52:56 +00:00
```
2020-01-19 02:51:33 +00:00
PLEASE NOTE, THERE ARE DEFAULT TEST VALUES FOR A POSTAL SERVER
PLEASE REMOVE THESE IF YOU DONT HAVE A POSTAL BACKEND TO TEST FROM!
2020-01-19 02:52:56 +00:00
```
2020-01-19 02:51:33 +00:00
[For more information on Postal](https://github.com/postalhq/postal)
2020-01-19 02:52:22 +00:00
```
cd ${GOPATH}/src/git.minhas.io/asara/sudoscientist-go-backend
2020-01-21 01:06:32 +00:00
for i in settings/*.env; do source $i; done
2019-04-14 03:38:51 +00:00
export DB_HOST=$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" sudosci-db)
2020-01-18 19:58:55 +00:00
PSQL_QUERY_STRING="postgres://${DB_USER}:${DB_PW}@${DB_HOST}:${DB_PORT}/${DB_NAME}?sslmode=${DB_SSL}"
migrate -path migrations/ -database ${PSQL_QUERY_STRING} up
2019-04-14 03:38:51 +00:00
go get
go run main.go
```