Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Fix build.bat and Dockerfiles (#289)
Browse files Browse the repository at this point in the history
* Fix build .bat copying files to bin folder

Signed-off-by: maurineimirandazup <maurinei.miranda@zup.com.br>

* Fix to run with Docker

Signed-off-by: maurineimirandazup <maurinei.miranda@zup.com.br>

* Fix makefile to copy Dockerfile

Signed-off-by: maurineimirandazup <maurinei.miranda@zup.com.br>
  • Loading branch information
maurineimirandazup authored Oct 26, 2020
1 parent 3f4bc09 commit 3280926
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 95 deletions.
12 changes: 12 additions & 0 deletions aws/generate/terraform-project/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM alpine:3.12
USER root

RUN mkdir /rit
COPY . /rit
RUN sed -i 's/\r//g' /rit/set_umask.sh
RUN sed -i 's/\r//g' /rit/run.sh
RUN chmod +x /rit/set_umask.sh

WORKDIR /app
ENTRYPOINT ["/rit/set_umask.sh"]
CMD ["/rit/run.sh"]
95 changes: 49 additions & 46 deletions aws/generate/terraform-project/Makefile
Original file line number Diff line number Diff line change
@@ -1,46 +1,49 @@
# Go parameters
BIN_FOLDER=bin
SH=$(BIN_FOLDER)/run.sh
BAT=$(BIN_FOLDER)/run.bat
BIN_NAME=main
GOCMD=go
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
CMD_PATH=main.go
BIN_FOLDER_DARWIN=../$(BIN_FOLDER)/darwin
BIN_DARWIN=$(BIN_FOLDER_DARWIN)/$(BIN_NAME)
BIN_FOLDER_LINUX=../$(BIN_FOLDER)/linux
BIN_LINUX=$(BIN_FOLDER_LINUX)/$(BIN_NAME)
BIN_FOLDER_WINDOWS=../$(BIN_FOLDER)/windows
BIN_WINDOWS=$(BIN_FOLDER_WINDOWS)/$(BIN_NAME).exe


build: go-build sh-unix bat-windows

go-build:
cd src; mkdir -p $(BIN_FOLDER_DARWIN) $(BIN_FOLDER_LINUX) $(BIN_FOLDER_WINDOWS)
#LINUX
cd src; CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o '$(BIN_LINUX)' $(CMD_PATH)
#MAC
cd src; GOOS=darwin GOARCH=amd64 $(GOBUILD) -o '$(BIN_DARWIN)' $(CMD_PATH)
#WINDOWS 64
cd src; GOOS=windows GOARCH=amd64 $(GOBUILD) -o '$(BIN_WINDOWS)' $(CMD_PATH)

cp -r src/files $(BIN_FOLDER)/files

sh-unix:
echo '#!/bin/sh' > $(SH)
echo 'if [ $$(uname) = "Darwin" ]; then' >> $(SH)
echo ' "$$(dirname "$$0")"/darwin/$(BIN_NAME)' >> $(SH)
echo 'else' >> $(SH)
echo ' "$$(dirname "$$0")"/linux/$(BIN_NAME)' >> $(SH)
echo 'fi' >> $(SH)
chmod +x $(SH)

bat-windows:
echo '@ECHO OFF' > $(BAT)
echo 'SET mypath=%~dp0' >> $(BAT)
echo 'start /B /WAIT %mypath:~0,-1%/windows/main.exe' >> $(BAT)

test:
$(GOTEST) -short `go list ./... | grep -v vendor/`
# Go parameters
BIN_FOLDER=bin
SH=$(BIN_FOLDER)/run.sh
BAT=$(BIN_FOLDER)/run.bat
BIN_NAME=main
GOCMD=go
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
CMD_PATH=main.go
BIN_FOLDER_DARWIN=../$(BIN_FOLDER)/darwin
BIN_DARWIN=$(BIN_FOLDER_DARWIN)/$(BIN_NAME)
BIN_FOLDER_LINUX=../$(BIN_FOLDER)/linux
BIN_LINUX=$(BIN_FOLDER_LINUX)/$(BIN_NAME)
BIN_FOLDER_WINDOWS=../$(BIN_FOLDER)/windows
BIN_WINDOWS=$(BIN_FOLDER_WINDOWS)/$(BIN_NAME).exe


build: go-build sh-unix bat-windows docker

go-build:
cd src; mkdir -p $(BIN_FOLDER_DARWIN) $(BIN_FOLDER_LINUX) $(BIN_FOLDER_WINDOWS)
#LINUX
cd src; CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o '$(BIN_LINUX)' $(CMD_PATH)
#MAC
cd src; GOOS=darwin GOARCH=amd64 $(GOBUILD) -o '$(BIN_DARWIN)' $(CMD_PATH)
#WINDOWS 64
cd src; GOOS=windows GOARCH=amd64 $(GOBUILD) -o '$(BIN_WINDOWS)' $(CMD_PATH)

cp -r src/files $(BIN_FOLDER)/files

sh-unix:
echo '#!/bin/sh' > $(SH)
echo 'if [ $$(uname) = "Darwin" ]; then' >> $(SH)
echo ' "$$(dirname "$$0")"/darwin/$(BIN_NAME)' >> $(SH)
echo 'else' >> $(SH)
echo ' "$$(dirname "$$0")"/linux/$(BIN_NAME)' >> $(SH)
echo 'fi' >> $(SH)
chmod +x $(SH)

bat-windows:
echo '@ECHO OFF' > $(BAT)
echo 'SET mypath=%~dp0' >> $(BAT)
echo 'start /B /WAIT %mypath:~0,-1%/windows/main.exe' >> $(BAT)

docker:
cp Dockerfile set_umask.sh $(BIN_FOLDER)

test:
$(GOTEST) -short `go list ./... | grep -v vendor/`
99 changes: 50 additions & 49 deletions aws/generate/terraform-project/build.bat
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
:: Go parameters
echo off
SETLOCAL
SET BINARY_NAME=main
SET GOCMD=go
SET GOBUILD=%GOCMD% build
SET CMD_PATH=main.go
SET BIN_FOLDER=..\bin
SET DIST_WIN_DIR=%BIN_FOLDER%\windows
SET DIST_LINUX_DIR=%BIN_FOLDER%\linux
SET BIN_WIN=%BINARY_NAME%.exe
SET BAT_FILE=%BIN_FOLDER%\run.bat
SET SH_FILE=%BIN_FOLDER%\run.sh

:build
cd src
mkdir %DIST_WIN_DIR%
SET GO111MODULE=on
for /f %%i in ('go list -m') do set MODULE=%%i
CALL :windows
CALL :linux
if %errorlevel% neq 0 exit /b %errorlevel%
GOTO CP_DOCKER
GOTO DONE
cd ..

:windows
SET CGO_ENABLED=
SET GOOS=windows
SET GOARCH=amd64
%GOBUILD% -tags release -o %DIST_WIN_DIR%\%BIN_WIN% %CMD_PATH%
echo @ECHO OFF > %BAT_FILE%
echo SET mypath=%%~dp0 >> %BAT_FILE%
echo start /B /WAIT %%mypath:~0,-1%%/windows/main.exe >> %BAT_FILE%
GOTO DONE

:linux
SET CGO_ENABLED=0
SET GOOS=linux
SET GOARCH=amd64
%GOBUILD% -tags release -o %DIST_LINUX_DIR%\%BINARY_NAME% %CMD_PATH%
echo "$(dirname "$0")"/linux/%BINARY_NAME% > %SH_FILE%
GOTO DONE

:CP_DOCKER
copy ..\Dockerfile %BIN_FOLDER%
copy ..\set_umask.sh %BIN_FOLDER%
GOTO DONE
:DONE
:: Go parameters
echo off
SETLOCAL
SET BINARY_NAME=main
SET GOCMD=go
SET GOBUILD=%GOCMD% build
SET CMD_PATH=main.go
SET BIN_FOLDER=..\bin
SET DIST_WIN_DIR=%BIN_FOLDER%\windows
SET DIST_LINUX_DIR=%BIN_FOLDER%\linux
SET BIN_WIN=%BINARY_NAME%.exe
SET BAT_FILE=%BIN_FOLDER%\run.bat
SET SH_FILE=%BIN_FOLDER%\run.sh

:build
cd src
xcopy /e/h/i files %BIN_FOLDER%\files
mkdir %DIST_WIN_DIR%
SET GO111MODULE=on
for /f %%i in ('go list -m') do set MODULE=%%i
CALL :windows
CALL :linux
if %errorlevel% neq 0 exit /b %errorlevel%
GOTO CP_DOCKER
GOTO DONE
cd ..

:windows
SET CGO_ENABLED=
SET GOOS=windows
SET GOARCH=amd64
%GOBUILD% -tags release -o %DIST_WIN_DIR%\%BIN_WIN% %CMD_PATH%
echo @ECHO OFF > %BAT_FILE%
echo SET mypath=%%~dp0 >> %BAT_FILE%
echo start /B /WAIT %%mypath:~0,-1%%/windows/main.exe >> %BAT_FILE%
GOTO DONE

:linux
SET CGO_ENABLED=0
SET GOOS=linux
SET GOARCH=amd64
%GOBUILD% -tags release -o %DIST_LINUX_DIR%\%BINARY_NAME% %CMD_PATH%
echo "$(dirname "$0")"/linux/%BINARY_NAME% > %SH_FILE%
GOTO DONE

:CP_DOCKER
copy ..\Dockerfile %BIN_FOLDER%
copy ..\set_umask.sh %BIN_FOLDER%
GOTO DONE
:DONE
3 changes: 3 additions & 0 deletions aws/generate/terraform-project/set_umask.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
umask 0011
$1
Empty file.

0 comments on commit 3280926

Please sign in to comment.