Skip to content

Commit

Permalink
Add gitlab-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibautBremand committed Aug 10, 2020
1 parent 95cc077 commit 4b141ca
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 4 deletions.
72 changes: 72 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
variables:
DOCKER_HOST: tcp://docker:2375

stages:
- "test"
- "build"
- "client"
- "deploy"

test:
stage: "test"
image: "golang:1.13.4-buster"
script:
- "make test"

build:
stage: "build"
image: "golang:1.13.4-buster"
script:
- "make build"
artifacts:
paths:
- "server"

client:
stage: "client"
image: "debian:buster"

before_script:
- |
apt-get update -qq && \
apt-get install -y -qq git && \
apt-get install -y -qq npm
script:
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/thibautbremand/2D-MMORPG-client.git
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/thibautbremand/2D-MMORPG-character-creator.git
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/thibautbremand/assets.git
- cd 2D-MMORPG-client
- git submodule update --init --recursive
- npm install
- npm run build
- cd ../2D-MMORPG-character-creator
- git submodule update --init --recursive
artifacts:
paths:
- 2D-MMORPG-client
- $ADMIN_PATH

deploy:
stage: "deploy"
image: docker:latest
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- |
docker build -t registry.gitlab.com/thibautbremand/2d-mmorpg-server \
--build-arg DB_NAME=$DB_NAME \
--build-arg DB_PASS=$DB_PASS \
--build-arg DB_USER=$DB_USER \
--build-arg DB_HOST=$DB_HOST \
--build-arg DB_PORT=$DB_PORT \
--build-arg REDIS_HOST=$REDIS_HOST \
--build-arg REDIS_PORT=$REDIS_PORT \
--build-arg REDIS_PASS=$REDIS_PASS \
--build-arg REDIS_DB=$REDIS_DB \
--build-arg CLIENT_PATH=$CLIENT_PATH \
--build-arg ADMIN_PATH=$ADMIN_PATH \
.
- docker push registry.gitlab.com/thibautbremand/2d-mmorpg-server
services:
- "docker:18.09-dind"
42 changes: 41 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,48 @@ FROM debian:buster
RUN apt-get update && \
apt-get upgrade -y

# Deploy component
ARG DB_NAME
ARG DB_PASS
ARG DB_USER
ARG DB_HOST
ARG DB_PORT
ARG REDIS_HOST
ARG REDIS_PORT
ARG REDIS_PASS
ARG REDIS_DB
ARG CLIENT_PATH
ARG ADMIN_PATH

ENV DB_NAME=$DB_NAME
ENV DB_PASS=$DB_PASS
ENV DB_USER=$DB_USER
ENV DB_HOST=$DB_HOST
ENV DB_PORT=$DB_PORT
ENV REDIS_HOST=$REDIS_HOST
ENV REDIS_PORT=$REDIS_PORT
ENV REDIS_PASS=$REDIS_PASS
ENV REDIS_DB=$REDIS_DB
ENV ADMIN_PATH=$ADMIN_PATH

ENV C_PATH=$CLIENT_PATH
ENV CLIENT_PATH=/app/$CLIENT_PATH

ENV A_PATH=$ADMIN_PATH
ENV ADMIN_PATH=/app/$ADMIN_PATH

RUN mkdir /app
COPY server /app

RUN mkdir -p ${CLIENT_PATH}client
RUN mkdir -p ${CLIENT_PATH}client/Universal-LPC-spritesheet
RUN mkdir -p ${CLIENT_PATH}client/tilesets

COPY 2D-MMORPG-client/Universal-LPC-spritesheet ${CLIENT_PATH}client/Universal-LPC-spritesheet
COPY assets/tilesets ${CLIENT_PATH}client/tilesets
COPY $C_PATH ${CLIENT_PATH}client
COPY /tilesets ${CLIENT_PATH}client/tilesets

RUN mkdir -p ${ADMIN_PATH}admin
COPY $A_PATH ${ADMIN_PATH}admin

CMD [ "/app/server" ]
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
test:
$(info No tests!)
$(info No tests!)

build:
go build -o server main.go
5 changes: 5 additions & 0 deletions db/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func Start() {
Password: pass,
DB: db,
})

_, err = Redis.Ping().Result()
if err != nil {
log.Fatalf("error while connecting to Redis: %v", err)
}
}

// Return the list of keys that start with the given prefix
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"log"
"server/db"
"server/webserver"
Expand All @@ -12,7 +11,7 @@ import (
// startDatabases connects to the storage and the redis.
func startDatabases() {
if err := db.Open(); err != nil {
fmt.Printf("error %v", err)
log.Fatalf("error %v", err)
}
db.Start()
}
Expand Down
6 changes: 6 additions & 0 deletions webserver/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ func startHub() {
r.HandleFunc("/newgamemap", newGamemap).Methods("POST")
r.HandleFunc("/character", serveCharacterPage)
r.HandleFunc("/gamemap", serveGamemapPage)
r.HandleFunc("/test", func(writer http.ResponseWriter, request *http.Request) {
_, _ = writer.Write([]byte("Hello World"))
})

log.Printf("Server started")
}

// serveHome serves the html frontpage.
Expand All @@ -66,6 +71,7 @@ func serveHome(w http.ResponseWriter, r *http.Request) {
if clientPath[len(clientPath)-1:] != "/" {
clientPath = fmt.Sprintf("%s/", clientPath)
}

http.ServeFile(w, r, fmt.Sprintf("%sclient/home.html", clientPath))
}

Expand Down

0 comments on commit 4b141ca

Please sign in to comment.