Skip to content

Commit

Permalink
Dev. Add files to make dev build and test run
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiy.safronov committed Jul 26, 2022
1 parent f821873 commit e351c91
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
80 changes: 80 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Makefile for OCPP Example project

# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod

# Folders definitions
BINARY_FOLDER=bin

# Get a short hash of the git had for building images.
VERSION = 1.0
TAG = $$(git rev-parse --short HEAD)
APP_NAME=ocpp_example
IMAGE_NAME = "${APP_NAME}"
DOCKERFILE = "Dockerfile"
PROJECT_PATH = $(shell pwd)

define docker-build =
docker build -t ${IMAGE_NAME}:${VERSION} -f ${DOCKERFILE} .
docker run --rm \
--name toolbox-ocppexample-tests \
-v ${PROJECT_PATH}:/go/ocppexample \
${IMAGE_NAME}:${VERSION} \
make -C /go/ocppexample $(1)
endef

define docker-run =
docker run --rm \
--name toolbox-ocppexample-tests \
-v ${PROJECT_PATH}:/go/ocppexample \
-v ${PROJECT_PATH}/logs:/tmp/logs \
-v ${PROJECT_PATH}/example/configs.json:/tmp/configs.json \
-p "9033:8080" \
${IMAGE_NAME}:${VERSION} \
$(1)
endef


clean:
$(GOCLEAN)
rm -rf $(BINARY_FOLDER)

modinit:
$(GOMOD) init github.com/CoderSergiy/ocpp16-go

deps:
export GO111MODULE=on
$(GOGET) github.com/julienschmidt/httprouter
$(GOGET) github.com/gorilla/websocket
$(GOGET) github.com/CoderSergiy/golib/logging
$(GOGET) github.com/CoderSergiy/golib/timerlib
$(GOGET) github.com/CoderSergiy/golib/tools

build:
$(GOBUILD) -o $(BINARY_FOLDER)/server -v ./server.go

depsupdate:
go get -v -t ./...

buildall: depsupdate build

# Command using Docker container

dockerclean:
$(call docker-build, "clean")

dockerprojectsetup:
# Call once when setup project
$(call docker-build, "modinit")

dockerbuild:
$(call docker-build, "buildall")

dockerserverrun:
$(call docker-build, "buildall")
$(call docker-run, "$(BINARY_FOLDER)/server")
7 changes: 7 additions & 0 deletions dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM golang:1.18

ENV GOPATH /go
ENV PATH /go/bin:$PATH
RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin

WORKDIR /go/ocppexample

0 comments on commit e351c91

Please sign in to comment.