Replace the makefile with a shell script

This commit is contained in:
Grégoire Delattre 2019-05-10 19:42:11 +02:00
parent 8d94340f60
commit 9424780861
3 changed files with 81 additions and 85 deletions

View File

@ -1,46 +0,0 @@
.PHONY: docker migration dev clean test build_docker_image
DB_USER=test
DB_PASS=test
DB_DSN_DEV=postgres://$(DB_USER):$(DB_PASS)@127.0.0.1:5432/dev?sslmode=disable
MIGRATION=migrate -database '$(DB_DSN_DEV)'
MIGRATION_SCHEMA=./migrations
DOCKER_COMPOSE_FILE=./docker/docker-compose.yml
DOCKER_COMPOSE=docker-compose -f $(DOCKER_COMPOSE_FILE)
build-prepare:
mkdir -p ./build/public/img/movies
build: build-prepare
go build -o ./build/canape src/main.go
watch-go: build-prepare
CONFIG_FILE="./config.yml" fresh -c fresh.conf
docker:
$(DOCKER_COMPOSE) up -d
sleep 8
build_docker_image:
rm -rf canapeapp
mkdir canapeapp
cp -R docker/run.sh canapeapp/run.sh
cp -R migrations canapeapp/migrations
cp $$GOPATH/bin/migrate canapeapp/migrate
yarn build
go build -v -o canapeapp/app backend/*.go
docker build --tag canapeapp:latest --file docker/Dockerfile-production .
rm -rf canapeapp
migration-schema: docker
$(MIGRATION) -path $(MIGRATION_SCHEMA) up
migration: migration-schema
dev: docker migration watch-go
clean:
-rm -r ./build
$(DOCKER_COMPOSE) stop
$(DOCKER_COMPOSE) rm --force -v

View File

@ -12,41 +12,25 @@ sudo npm install -g yarn
yarn install yarn install
``` ```
### Go tools && Dependencies
As there is no versioning yet, you need to manually go get all the packages
```
go get ./...
```
go tools:
```
go get -v -u github.com/pilu/fresh
GO111MODULE=off go get -tags 'postgres' -u github.com/golang-migrate/migrate/cmd/migrate
```
## Dev ## Dev
#### Check your config.yml file #### Check your config.yml file
#### Run server #### Run the backend
``` ```sh
make dev ./dev.sh back
``` ```
#### Run javascript tools #### Run the frontend
``` ```sh
yarn start ./dev.sh front
``` ```
## Connect to the database ## Connect to the database
``` ```sh
docker run -it --rm -e PGPASSWORD=test --link canape_postgresql_dev:postgres postgres:9.5 psql -h postgres -U test -d dev docker run -it --rm -e PGPASSWORD=test --link canape_postgresql_dev:postgres postgres:9.5 psql -h postgres -U test -d dev
``` ```
@ -54,7 +38,7 @@ docker run -it --rm -e PGPASSWORD=test --link canape_postgresql_dev:postgres pos
Connect to the database and enter this sql queries: Connect to the database and enter this sql queries:
``` ```sh
INSERT INTO users (name, hash, admin, activated) VALUES ('test', '$2a$10$QHx07iyuxO1RcehgtjMgjOzv03Bx2eeSKvsxkoj9oR2NJ4cklh6ue', false, true); INSERT INTO users (name, hash, admin, activated) VALUES ('test', '$2a$10$QHx07iyuxO1RcehgtjMgjOzv03Bx2eeSKvsxkoj9oR2NJ4cklh6ue', false, true);
INSERT INTO users (name, hash, admin, activated) VALUES ('admin', '$2a$10$qAbyDZsHtcnhXhjhQZkD2uKlX72eMHsX8Hi2Cnl1vJUqHQiey2qa6', true, true); INSERT INTO users (name, hash, admin, activated) VALUES ('admin', '$2a$10$qAbyDZsHtcnhXhjhQZkD2uKlX72eMHsX8Hi2Cnl1vJUqHQiey2qa6', true, true);
``` ```
@ -69,19 +53,6 @@ Users:
## Run the tests ## Run the tests
```sh
``` go test ./...
make test
```
## To clean up
```
make clean
```
## Production build
```
yarn build
``` ```

71
dev.sh Executable file
View File

@ -0,0 +1,71 @@
#!/bin/sh
set -e
DB_USER="test"
DB_PASS="test"
DB_DSN_DEV="postgres://$DB_USER:$DB_PASS@127.0.0.1:5432/dev?sslmode=disable"
CONFIG_FILE=config.yml
MIGRATION_SCHEMA=./migrations
DOCKER_COMPOSE_FILE=./docker/docker-compose.yml
_usage() {
echo "Usage:"
echo "$0 [back|front]"
exit 1
}
_check_command() {
command -v "$1" >/dev/null 2>/dev/null
}
_ensure_command() {
_check_command "$1" && return 0
echo "Please install $1 first"
exit 1
}
_migrate() {
migrate -database "$DB_DSN_DEV" "$@"
}
_ensure_command go
_ensure_command docker
_ensure_command docker-compose
_ensure_command yarn
_check_command migrate || {
echo "Installing migrate"
GO111MODULE=off \
go get -tags 'postgres' \
-u -v github.com/golang-migrate/migrate/cmd/migrate
}
_check_command fresh || {
echo "Installing fresh"
GO111MODULE=off \
go get -u -v github.com/pilu/fresh
}
[ -f "$CONFIG_FILE" ] || {
echo "Please setup the canape configuration in $CONFIG_FILE"
exit 1
}
case $1 in
back)
docker-compose -f "$DOCKER_COMPOSE_FILE" up -d
# Wait for the container to be up
_migrate -path "$MIGRATION_SCHEMA" up
CONFIG_FILE="./config.yml" fresh -c fresh.conf
;;
front)
yarn install
yarn start
;;
*)
_usage
;;
esac