Skip to content

Commit

Permalink
Merge pull request pathwar#48 from pathwar/dev/moul/all-models
Browse files Browse the repository at this point in the history
feat: define all models
  • Loading branch information
moul authored Mar 14, 2019
2 parents 1c4000e + 54022dd commit d1d015f
Show file tree
Hide file tree
Showing 14 changed files with 5,768 additions and 1,022 deletions.
5 changes: 3 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ jobs:
- setup_remote_docker:
docker_layer_caching: true
- run: docker build -t pathwar/pathwar .
- run: make docker.integration
- run: make docker.integration
- run: docker build -t pathwar/pathwar:test ./test
- run: make integration.run
- run: make integration.run # yes, again
- run: docker-compose logs

workflows:
Expand Down
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.circleci/
test/
.git/
*~
.#*
Expand Down
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# builder
FROM golang:1.11-alpine as builder
FROM golang:1.12-alpine as builder
RUN apk --no-cache --update add nodejs-npm make gcc g++ musl-dev openssl-dev git
ENV GO111MODULE=on
COPY go.* /go/src/pathwar.pw/
ENV GO111MODULE=on GOPROXY=https://goproxy.io
COPY go.mod go.sum /go/src/pathwar.pw/
WORKDIR /go/src/pathwar.pw
RUN go get .
COPY . .
RUN touch .proto.generated && make install

# runtime
FROM alpine:3.8
RUN apk --no-cache --update add openssl
RUN apk --no-cache --update add openssl wget bash
RUN wget https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh && chmod +x wait-for-it.sh
COPY --from=builder /go/bin/pathwar.pw /bin/pathwar.pw
ENTRYPOINT ["/bin/pathwar.pw"]
CMD ["server"]
Expand Down
41 changes: 31 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,34 @@ help:
sed 's/^/ $(HELP_MSG_PREFIX)make /'

.PHONY: run
run: $(BIN)
run: $(BIN) mysql.up
$(BIN) server $(RUN_OPTS)

.PHONY: install
install: $(BIN)
$(BIN): .proto.generated $(PWCTL_OUT_FILES) $(OUR_SOURCES)
go install -v

.PHONY: mysql.up
mysql.up:
docker-compose up -d mysql
@echo "Waiting for mysql to be ready..."
@while ! mysqladmin ping -h127.0.0.1 -P3306 --silent; do sleep 1; done
@echo "Done."

.PHONY: mysql.down
mysql.down:
docker-compose stop mysql || true
docker-compose rm -f -v mysql || true

.PHONY: mysql.shell
mysql.shell:
mysql -h127.0.0.1 -P3306 -uroot -puns3cur3 pathwar

.PHONY: mysql.dump
mysql.dump:
mysqldump -h127.0.0.1 -P3306 -uroot -puns3cur3 pathwar

.PHONY: clean
clean:
rm -f $(GENERATED_FILES) .proto.generated
Expand All @@ -61,13 +81,13 @@ _ci_prepare:
.PHONY: generate
generate: .proto.generated
.proto.generated: $(OUR_PROTOS)
rm -f $(GENERATED_FILES)
rm -f $(GENERATED_PB_FILES)
go mod vendor
docker run \
--user="$(shell id -u)" \
--volume="$(PWD):/go/src/pathwar.pw" \
--workdir="/go/src/pathwar.pw" \
--pwctl="sh" \
--entrypoint="sh" \
--rm \
pathwar/protoc:v1 \
-xec "make _proto_generate"
Expand All @@ -93,13 +113,14 @@ test: .proto.generated

.PHONY: docker.build
docker.build:
docker build -t pathwar/pathwar .

.PHONY: docker.integration
docker.integration:
docker-compose -f ./test/docker-compose.yml up -d server
docker-compose -f ./test/docker-compose.yml run client
docker-compose -f ./test/docker-compose.yml down
docker build -t pathwar/pathwar:latest .
docker build -t pathwar/pathwar:test ./test

.PHONY: integration.run
integration.run:
docker-compose -f ./docker-compose.yml -f ./test/docker-compose.yml up -d --no-build server
docker-compose -f ./docker-compose.yml -f ./test/docker-compose.yml run --no-deps client
docker-compose -f ./docker-compose.yml -f ./test/docker-compose.yml down

.PHONY: integration
integration:
Expand Down
24 changes: 19 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@ version: '2.3'

services:
server:
&server
image: pathwar/pathwar
command: server
#depends_on:
# - mysql
image: pathwar/pathwar:latest
build: .
entrypoint:
- "/bin/bash"
- "-c"
command:
- "./wait-for-it.sh mysql:3306 -- /bin/pathwar.pw server --sql-config='root:uns3cur3@tcp(mysql:3306)/pathwar?charset=utf8'"
depends_on:
- mysql
ports:
- 8000

mysql:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
restart: always
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: uns3cur3
MYSQL_DATABASE: pathwar
42 changes: 40 additions & 2 deletions entity/entity.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,49 @@
package entity

func ByName(name string) interface{} {
return AllMap()[name]
}

func AllMap() map[string]interface{} {
return map[string]interface{}{
"Achievement": Achievement{},
"Coupon": Coupon{},
"Event": Event{},
"Hypervisor": Hypervisor{},
"LevelFlavor": LevelFlavor{},
"LevelInstance": LevelInstance{},
"LevelSubscription": LevelSubscription{},
"Level": Level{},
"Notification": Notification{},
"ShopItem": ShopItem{},
"TeamMember": TeamMember{},
"Team": Team{},
"TournamentTeam": TournamentTeam{},
"Tournament": Tournament{},
"UserSession": UserSession{},
"User": User{},
"WhoswhoAttempt": WhoswhoAttempt{},
}
}

func All() []interface{} {
return []interface{}{
Achievement{},
Coupon{},
Event{},
Hypervisor{},
LevelFlavor{},
LevelInstance{},
LevelSubscription{},
Level{},
UserSession{},
User{},
Notification{},
ShopItem{},
TeamMember{},
Team{},
TournamentTeam{},
Tournament{},
UserSession{},
User{},
WhoswhoAttempt{},
}
}
Loading

0 comments on commit d1d015f

Please sign in to comment.