-
Notifications
You must be signed in to change notification settings - Fork 11
Local Development Setup
vivekweb2013 edited this page Jun 12, 2022
·
2 revisions
There are several ways to start the api service locally. Refer any one of the following method
Make sure docker is installed on the system. Below commands use docker to start the database container
make network
make postgres
make createdbcp config.yaml .config.yamlMake sure that the .config.yaml file is configured correctly & database is up.
go run main.go migrateup
go run main.go servego buildThis will build the service & generate executable file.
cp config.yaml .config.yamlMake sure that the .config.yaml file is configured correctly & database is up.
./batnoter-api migrateup
./batnoter-api servedocker build -t batnoter-api:latest .# setup pre-requisite
docker network create gn-network
docker run --name postgres12 --network gn-network -p 5432:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=secret -d postgres:12-alpine
docker exec -it postgres12 createdb --username=root --owner=root gn_db
docker exec -it postgres12 sh -c "psql -U root -d gn_db -c \"CREATE SCHEMA IF NOT EXISTS batnoter;\" "
# inspect the ip-address of postgres container
docker inspect <postgres-container-id>
# run migration (replace '<postgres-container-ip>' with the actual ip-address)
docker run --network gn-network -it \
-e DATABASE_HOST='<postgres-container-ip>' \
-e DATABASE_PORT='5432' \
-e DATABASE_DBNAME='gn_db' \
-e DATABASE_USERNAME='root' \
-e DATABASE_PASSWORD='secret' \
-e DATABASE_SSLMODE='disable' \
-e DATABASE_DEBUG='true' \
batnoter-api /app/batnoter-api migrateup
# start server (replace '<postgres-container-ip>' with the actual ip-address)
docker run --network gn-network -it \
-e SECRETKEY='secret' \
-e DATABASE_HOST='<postgres-container-ip>' \
-e DATABASE_PORT='5432' \
-e DATABASE_DBNAME='gn_db' \
-e DATABASE_USERNAME='root' \
-e DATABASE_PASSWORD='secret' \
-e DATABASE_SSLMODE='disable' \
-e DATABASE_DEBUG='true' \
-e HTTPSERVER_DEBUG='true' \
-e OAUTH2_GITHUB_CLIENTID='<github_client_id>' \
-e OAUTH2_GITHUB_CLIENTSECRET='<github_client_secret>' \
-e OAUTH2_GITHUB_REDIRECTURL='http://localhost:3000/api/v1/oauth2/github/callback' \
-p 8080:8080 \
batnoter-apiThis will start the server on the specified port.