RentBook Project
Aplikasi yang membantu manajement untuk mengirim dan menerima buku antara pengguna.
Arsitekture dan Task:
Setup Environment Variable
Env yang di perlukan agar aplikasi bisa berjalan .env
### DATABASE ###
DB_DRIVER=mysql
DB_USERNAME=alterra_rent_book
DB_PASSWORD=test
DB_NAME=alterra_rent_book_db
DB_ADDRESS='127.0.0.1'
DB_PORT=3306
MYSQL_ROOT_PASSWORD=root
### Redis ###
REDIS_ADDRESS=localhost
REDIS_PORT=6379
REDIS_USERNAME="alterra_rent_book"
REDIS_PASSWORD="password"
### APP CONFIGURATION ###
APP_HOST='127.0.0.1'
APP_PORT=8000
JWT_SECRET=secret
API_ENDPOINT='127.0.0.1:8000'
Note:
API_ENDPOINT
is using by swagger gui to where are the endpoint
Deploy to Server (Dockerize)
Untuk deploy ke server pastikan docker dan docker compose terinstall ke dalam server
pada env varibel ubah API_ENDPOINT
sesuai dengan nama host server.
Run In Server:
- Build docker image for the source code
- Push docker image into repository provider like hub.docker.com
- copy the
.env
and docker-compose the replace the docker-compose with bellow
web-app:
restart: always
build:
dockerfile: Dockerfile
context: .
with
web-app:
restart: always
image: <repo_name>/<image_name>:<tag>
Note: Replace <repo_name>, <image_name> and with own docker hub configuration
Testing
- Run All test
go test ./...
- Run All test with coverage output
go test ./... -v -coverprofile=coverage.out
- Output the coverage into html file
go tool cover -html=coverage.out
Bootup Server (Amazon ES2)
To bootup server is easy after all above requirement is fullfilled. The important part is
setup inbounding incoming request security to allow the HTTP and HTTPS Port
- Start the server just
docker-compose up -d
The app now run in server and start automaticaly in background
Deploy Cli Cmd
chmod +x deploy.sh
./deploy.sh \
app_port=8000 \
app_name=go_book \
app_domain=gobook.satulayar.com \
mysql_root_password=root \
app_user=rentbook \
app_password=rentbook \
jwt_secret=secret \
app_image="ghcr.io/alta-be7-i-kadek-adi-gunawan/rentbook" \
app_tag=main