-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
155f650
commit 3e30282
Showing
6 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.DS_Store | ||
bin/* | ||
.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.DS_Store | ||
bin/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM golang:1.14 as builder | ||
|
||
ARG BUILD_TIME=0 | ||
ARG BUILD_VERSION=0 | ||
|
||
WORKDIR /app | ||
|
||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
COPY . ./ | ||
|
||
# Make it runnable on alpine | ||
RUN CGO_ENABLED=0 GOOS=linux go build \ | ||
-ldflags="-X 'main.BuildTime=${BUILD_TIME}' -X 'main.BuildVersion=${BUILD_VERSION}'" \ | ||
-a -installsuffix cgo -o woke . | ||
|
||
###################### | ||
|
||
FROM alpine:latest | ||
COPY --from=builder /app/woke /woke | ||
COPY default.yaml /default.yaml | ||
ENTRYPOINT [ "/woke" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
FROM golang:1.14 | ||
|
||
RUN apt-get update && apt-get install -y inotify-tools | ||
|
||
ENV ROOT_PATH /go/src/github.com/caitlinelfring/woke | ||
WORKDIR $ROOT_PATH | ||
COPY . $ROOT_PATH | ||
|
||
RUN go build ./... | ||
|
||
ENTRYPOINT ["./autoreload.sh"] | ||
CMD ["woke"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
build: | ||
docker build -t woke -f Dockerfile.dev . | ||
|
||
run: | ||
docker run --rm -it \ | ||
-v `pwd`:/go/src/github.com/caitlinelfring/woke \ | ||
woke bin/woke "./*.go ./**/*.go ./**/**/*.go" | ||
|
||
.PHONY: build run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/bash | ||
# Autoreloads go application on file changes | ||
# From https://github.com/caitlinelfring/go_autoreload | ||
|
||
TARGET=${1:-"app"} | ||
FILES_TO_WATCH=${2:-"./*.go"} | ||
|
||
wait_for_changes() { | ||
echo "Waiting for changes" | ||
if [ "$(uname)" == "Darwin" ]; then | ||
fswatch -e ".*" -i "\\.go$" -x -r -1 . | ||
else | ||
# FILES_TO_WATCH can be something like: ./*.go ./**/*.go ./**/**/*.go | ||
# depending on how long the folder structure is. | ||
# unfortunately, inotifywait can't recursively watch specific file types | ||
inotifywait -e modify -e create -e delete -e move $FILES_TO_WATCH | ||
fi | ||
} | ||
|
||
build() { | ||
echo "Rebuilding..." | ||
rm -vf $TARGET | ||
go build -v -o $TARGET | ||
} | ||
|
||
kill_server() { | ||
if [[ -n $SERVER_PID ]]; then | ||
echo | ||
echo "Stopping server (PID: $SERVER_PID)" | ||
kill $SERVER_PID | ||
fi | ||
} | ||
|
||
serve() { | ||
echo "Starting server" | ||
./$TARGET & | ||
SERVER_PID=$! | ||
} | ||
|
||
# Exit on ctrl-c (without this, ctrl-c would go to inotifywait, causing it to | ||
# reload instead of exit): | ||
trap "exit 0" SIGINT SIGTERM | ||
trap kill_server "EXIT" | ||
|
||
build | ||
serve | ||
while wait_for_changes; do | ||
kill_server | ||
if ! build; then | ||
echo "Error building server" | ||
continue | ||
fi | ||
serve | ||
done |