Coder Social home page Coder Social logo

compiledaemon's Introduction

Very simple Compile Daemon for Go GoDoc

Watches your .go files in a directory and invokes go build if a file changed. Nothing more.

Usage:

$ ./CompileDaemon -directory=yourproject/

Installation

You can use the go tool to install CompileDaemon:

go get github.com/githubnemo/CompileDaemon

Development

You need to use Go 1.16 or higher to build Compile Daemon, and you need to set the env var GO111MODULE=on, which enables you to develop outside of $GOPATH/src.

Command Line Options

Option Default Description
actions
-build=… go build Specify the command to run when rebuilding is required.
-command=… none Specify the command to run after a succesful build. The default is to run nothing. This command is issued with the working directory set to -directory.
file selection
-directory=… . Which directory to watch.
-recursive=… true Recurse down the specified directory
-exclude-dir=… none Do not watch directories matching this glob pattern, e.g. ".git". You may have multiples of this flag.
-exclude=… none Exclude files matching this glob pattern, e.g. ".#*" ignores emacs temporary files. You may have multiples of this flag.
-include=… none Include files whose last path component matches this glob pattern. You may have multiples of this flag.
-pattern=… (.+\.go|.+\.c)$ A regular expression which matches the files to watch. The default watches .go and .c files.
file watch
-polling=… false Use polling instead of FS notifications to detect changes. Default is false
-polling-interval=… 100 Milliseconds of interval between polling file changes when polling option is selected
misc
-color=_ false Colorize the output of the daemon's status messages.
-log-prefix=_ true Prefix all child process output with stdout/stderr labels and log timestamps.
-graceful-kill=_ false On supported platforms, send the child process a SIGTERM to allow it to exit gracefully if possible.

Examples

In its simplest form, the defaults will do. With the current working directory set to the source directory you can simply…

$ CompileDaemon

… and it will recompile your code whenever you save a source file.

If you want it to also run your program each time it builds you might add…

$ CompileDaemon -command="./MyProgram -my-options"

… and it will also keep a copy of your program running. Killing the old one and starting a new one each time you build.

You may find that you need to exclude some directories and files from monitoring, such as a .git repository or emacs temporary files…

$ CompileDaemon -exclude-dir=.git -exclude=".#*" …

If you want to monitor files other than .go and .c files you might…

$ CompileDaemon -include=Makefile -include="*.less" -include="*.tmpl"

Security Considerations

Beware that, in case you are using CompileDaemon in production to rebuild a binary (please explain to me why you would do this, but carry on), an attacker with write access is able to insert arbitrary code into your binary. So make sure that you secure write access to the file system appropriately.

Common Issues

Too many open files

If you get an error for too many open files, you might wish to exclude your .git, .hg, or similar VCS directories using -exclude-dir=…. This is common on OS X and BSD platforms where each watched file consumes a file descriptor.

If you still have too many open files, then you need to raise your process's file limit using the ulimit command. Something like ulimit -n 1024 will probably take care of it. There is also a sysctl based limit which you may reach and need to adjust.

filepath.Walk() no space left on device

As described in this issue it might happen that you run out of inotify watchers which are limited by your system configuration. Please consider increasing them as is documented here.

Docker + Mac OS X

Some issues (here and here) report that changes on Docker volumes under Mac OS X are not reported.

There seem to be issues with either the implementation of the bind file system mount between Mac OS X hosts and Docker containers or in fsnotify/fsnotify or a combination of both. As long as this is not resolved, a possible workaround is to use polling:

CompileDaemon -polling

This will actively watch for changes, so it naturally uses more CPU resources. You can tune the polling interval to your liking using the -polling-interval=N parameter but be advised: you should never use this in production as it is simply too wasteful.

Project Details

Credits

CompileDaemon was written by githubnemo.

Code and documentation was contributed by jimstudt.

Repository

CompileDaemon is kept at https://github.com/githubnemo/CompileDaemon

License

CompileDaemon is licensed under the BSD Two Clause License

compiledaemon's People

Contributors

darinkrauss avatar directive-cary avatar gavbaa avatar githubnemo avatar hursungyun avatar jimstudt avatar justonia avatar kworm83 avatar mbrukman avatar olostan avatar quentinperez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

compiledaemon's Issues

macos firewall issues

When I run CompileDaemon -exclude-dir=./container_data -exclude-dir=./.git -exclude-dir=./docker -exclude-dir=./migrations, my go app (local webserver) doesn't seem to work.

When I run go run . I get a macos firewall allow dialog. Once I click "allow", it works.

image

How can I get CompileDaemon to display the firewall dialog?

Flush logging buffer before printing CompileDaemon output

Since the logger buffer isn't flushed until another newline is found it's possible that the output that CompileDaemon generates can be affected by ANSII escape sequences that haven't been terminated due to no newline being printed.

For example, a program that writes output with color, writes a newline, then immediately writes the color reset escape sequence. Because the output is buffered the reset escape sequence won't be written until a newline is outputted. However, if the program is terminated and restarted it will never write the reset escape sequence and the output from CompileDaemon (eg "Running build command!") will be affected by the previous escape sequence.

Obviously this could be fixed by outputting the reset sequence before writing a newline, but it seems like the 'correct' solution would be for this software to flush the buffer when a program is recompiled.

Additional arguments in build don't work

I'm using CompileDeamon in my Dockerfile.
I was using this command to only rebuild my app after changes:
CMD swag init -d src && CompileDaemon --build="go build src/main.go" --command="./main" --color

but I wanted to add also hot reloading with swagger recompile like:
CMD swag init -d src && CompileDaemon --build="swag init -d src && go build src/main.go" --command="./main" --color

and it not working correctly. When I run my docker-compose then this container starts rebuilding every second without any change in files. I discovered that the problem is with an additional flag added to swag init.

When I remove -d src then CompileDeamon is not rebuilding the app without a change in code (correct behavior), so I think it's something wrong with interpreting command arguments.

It's problematic for me because of the project structure and I have to specify a directory for swag to compile it correctly :)

PS. Thanks for your work, CompileDeamon is great :D

Clear screen before build

It's really annoying to search the console for the current output after multiple rebuilds, the console simply becomes a mess. It would be great to clear the console before approaching a new build, neither -build="reset && gb build all" nor multiple -build="reset" -build="gb build all" work though.

Any idea how to fix this?

CompileDeamon not found golang 1.18

Hi,

Cannot run CompileDeamon as Entrypoint of dockerfile with golang 1.18
Working on golang:1.17.8-alpine3.15 with same ENTRYPOINT

tested with go get github.com/githubnemo/CompileDaemon@latest

Hard stop not working on Windows

Hi,

while using CompileDaemon on Windows 10 Pro I encountered a strange problem. When I run it as follows

CompileDaemon.exe -command="hello.exe"

I get the following output

2017/07/21 06:24:36 Running build command!
2017/07/21 06:24:37 Build ok.
2017/07/21 06:24:37 Restarting the given command.
2017/07/21 06:24:37 stdout: RUNNING6
2017/07/21 06:24:44 Running build command!
2017/07/21 06:24:45 Build ok.
2017/07/21 06:24:45 Hard stopping the current process..
2017/07/21 06:24:45 Could not kill child process. Aborting due to danger of infinite forks.

For debugging purposes I compiled CompileDaemon myself and added a print statement under the kill statement of the process. There I get the following error message :

TerminateProcess: Access denied

Obviously it isn't possible to kill a process on Windows which was created by exec.Command. Do you have an idea what can be done to fix this problem?

Thanks,
Thomas

Build errors not shown on cmd line

When there are build errors, it only shows an overall status that there was an error. To actually find out what the errors are, I'm having to run the go build separately.

Allow option to NOT build

This is great to just have go run . re-run on a file change. It's perfect with the combination of a templating engine which rebuilds go files once the html files are updated.

However, CompileDaemon always compiles the binary when many times I only want to have go run executed with -command.

Is there any chance of providing an option to not build?

Install for go 1.18+

Go dropped go get for cmd-tools.

executing go install github.com/githubnemo/COmpileDaemon/cmd does not work.

Command to run and test at the same time

First: Thank you.

After reading documentation and options, I can't run and test at the same time.
I think that could be possible with this package since most of the time we (devs) need it.

Currently:

#!/bin/sh
CompileDaemon \
    -directory=. \
    -recursive=true \
    -build="go build -o server" \
    -command="./server -port=4000 -host=localhost" \
    -color=true

What I'm looking:

#!/bin/sh
CompileDaemon \
    -directory=. \
    -recursive=true \
    -build="go build -o server" \
    -command="./server -port=4000 -host=localhost && go test ./... " \
    -color=true

Sorry If I missed something from docs.
Thank you for your time.

golang:latest error

Good day,

I followed the Tut at https://levelup.gitconnected.com/docker-for-go-development-a27141f36ba9 great work... Thanks.

I kept getting this build error:
step 6/7
...
go build golang.org/x/sys/internal/unsafeheader: module requires Go 1.12
ERROR: Service 'go-docker-image' failed to build: The command '/bin/sh -c go get
github.com/githubnemo/CompileDaemon' returned a non-zero code: 1

I changed the Dockerfile from golang:latest to golang:1.2 and it did the trick.
(maybe you could correct this in your repo for others)

Any idea on Golang 1.14 support?
(Seems to be the issue for me anyways)

Thanks again in advance.
JP

CompileDaemon does not work with Docker on Vagrant.

Hello,

Please help, I don't know where is the issue but after changing file CompileDaemon does not re-compile go application.
Currently, I'm using Windows, I don't want to use docker desktop for Windows so I install docker on Vagrant.
Here is my Dockerfile-local

FROM golang:alpine

# Set necessary environmet variables needed for our image
ENV GO111MODULE=on \
    CGO_ENABLED=0 \
    GOOS=linux \
    GOARCH=amd64

WORKDIR /build
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .

RUN apk add git
RUN go get github.com/githubnemo/CompileDaemon
ENTRYPOINT CompileDaemon --build="go build -o bin cmd/apiserver/server.go" --command="./bin/server"

And this is docker-compose file

version: '3'
services:
  api-server:
    build:
      context: ./
      dockerfile: Dockerfile-${ENV}
    image: api_server:tag
    container_name: api-server
    hostname: api-server
    restart: always
    volumes:
      - ./:/build
    ports:
      - 8080:8080

I missed something, didn't I? Or It's a Vagrant problem (Vagrant does not forward file changing event to docker).

Thank you very much for any help and sorry for my English.

Terminate the program if a build fails

Currently the program is left running, so if the build fails, you have an old version of the program running. It happened to me multiple times that I tried to use the HTTP app and it looked like working, but then there was no expected change in its behavior. Only then I realized that the new code didn't compile. It would be better if the program would be terminated always (after the build, if it is successful a new version is stared, otherwise nothing is started) so that I would see errors when browser tries to connect to a new version.

At least provide a flag to enable this behavior.

Got error when go get

Hi, somehow I got this error when try to get this package:

# golang.org/x/sys/unix
../../../golang.org/x/sys/unix/syscall_darwin.go:81:9: undefined: readInt
../../../golang.org/x/sys/unix/syscall_darwin.go:85:9: undefined: readInt
../../../golang.org/x/sys/unix/syscall_darwin.go:89:9: undefined: readInt
../../../golang.org/x/sys/unix/syscall_darwin.go:159:14: undefined: sysctlmib
../../../golang.org/x/sys/unix/syscall_unix.go:232:9: undefined: anyToSockaddr
../../../golang.org/x/sys/unix/syscall_unix.go:311:15: undefined: anyToSockaddr
../../../golang.org/x/sys/unix/syscall_unix.go:421:10: undefined: UtimesNanoAt
../../../golang.org/x/sys/unix/syscall_unix.go:427:3: undefined: NsecToTimespec
../../../golang.org/x/sys/unix/syscall_unix.go:427:18: undefined: TimevalToNsec
../../../golang.org/x/sys/unix/syscall_unix.go:428:3: undefined: NsecToTimespec
../../../golang.org/x/sys/unix/syscall_unix.go:428:3: too many errors

fsnotify dependency resolves to empty fsnofity repo on github

As of two hours ago there's now an empty fsnotify repo on github that compile daemon resolves to as its dependency.
http://gopkg.in/fsnotify.v1 -> https://github.com/go-fsnotify/fsnotify

This smells of a package injection attack but it seems to not have materialized.

At the very least, this has broken CompileDaemon because it resolves to the wrong dependency.

The maintainers of gopkg.in will probably figure it out, but we thought we'd let you know :)

Security Best Practice

Hi!
I think this tool is very useful during development and testing, but there might be severe consequences if used in production.
In fact, if attackers would be able to upload arbitrary files, this would trigger re-building and running the malicious code just uploaded, leading to RCE (Remote Code Execution).
In practice, this would bring the same vulnerabilities affecting interpreted languages in go.

I suggest to place a banner in the README.md file, warning developers to be careful and don't use this tool in production environment.

Command fails space in arguments

In the command and I think the build although haven't tested
If you have a space in the option it will fail to run.

CompileDaemon --build="go build -o program main.go " --command="./program --option=\"1 2\""

Seems to split on spaces which is not always correct.

Install info in README.md

README.md is missing install part for quick start:

go get github.com/githubnemo/CompileDaemon

Even, if it's pretty much obvious. For go-lang newcomers, like me, it takes a bit of time to figure this out.

Beep on build error option

CompileDaemon is great. Thank you.

It could use an additional feature to beep if a build breaks. I'm using it while building a web app. I usually have it running on some terminal in the background and I never get to know if there is an error. I reload the web pages but go through the user steps, discover that the code has had no effect, and only then maybe check if the build had failed or not. So much time lost.
It would really help to have a configurable beep to alert me when the build fails.

Seems to break Atom?

I've managed to start up the CompileDaemon with minimal effort. It seems to work great!

If I make a change in Atom and then hit save, the CompileDaemon does it thing and rebuild/restart. The problem is, Atom immediately freezes as soon as this happens. Is this something you've observed?

include multiple directories

The project I'm working on has important files two folders back from where the main.go file is, so it would be nice to have something like -include-dir="../../core" to be able to monitor any changes on these files as well, since we work with them a lot.

Console not showing, echo server not restarting

The following code displays "test" on the terminal when running my go module without CompileDaemon:
fmt.Fprintf(os.Stdout, "test")

When using CompileDaemon using the following command, there is not output on the terminal:
${my_go_path}/CompileDaemon -directory={directory_to_track_changes_on} -command="go run {path_to_main_file}" -color=true

Additionally, part of the code that runs starts an echo server on a local port. When I make changes, although live reloading happens, the server isn't restarted.

package math/bits: unrecognized import path "math/bits" (import path does not begin with hostname)

Error comes up on newer versions of go like; 1.7<

The below dependency file contains math/bits which is causing related issue;
https://cs.opensource.google/go/x/sys/+/master:unix/affinity_linux.go;l=10?q=math%2Fbits&sq=&ss=go%2Fx%2Fsys

github.com/githubnemo/CompileDaemon (download)
github.com/fatih/color (download)
github.com/mattn/go-colorable (download)
github.com/mattn/go-isatty (download)
Fetching https://golang.org/x/sys/unix?go-get=1
Parsing meta tags from https://golang.org/x/sys/unix?go-get=1 (status code 200)
get "golang.org/x/sys/unix": found meta tag main.metaImport{Prefix:"golang.org/x/sys", VCS:"git", RepoRoot:"https://go.googlesource.com/sys"} at https://golang.org/x/sys/unix?go-get=1
get "golang.org/x/sys/unix": verifying non-authoritative meta tag
Fetching https://golang.org/x/sys?go-get=1
Parsing meta tags from https://golang.org/x/sys?go-get=1 (status code 200)
golang.org/x/sys (download)
package math/bits: unrecognized import path "math/bits" (import path does not begin with hostname)
github.com/fsnotify/fsnotify (download)
github.com/radovskyb/watcher (download)

license?

Not really an issue, but I'm curious - what is this licensed under?

Thanks.

Question: Live Reload & Delve debugging

I am using VSCode and Docker. I want to live reload a go api and use the delve debugger in the same container instance.

Here's what I have so far: https://github.com/ivorscott/go-delve-reload

In the docker-compose.yml file you will see two services api and debug api. One uses CompileDaemon, the other uses Delve. Both containers are based off the same "dev" build stage in a multi-stage scenario.

Whenever I tried combining both approaches within one container I had issues. Ideally I want to have both features in one container.

Fix skipping build command

When run with -build='', the following error occurs:

2021/01/10 16:51:52 Running build command!
2021/01/10 16:51:52 Error while building:

The following code in the build() function seems to be for conditionally skipping the build command:

CompileDaemon/daemon.go

Lines 151 to 158 in 39b144a

func build() bool {
log.Println(okColor("Running build command!"))
args := strings.Split(*flagBuild, " ")
if len(args) == 0 {
// If the user has specified and empty then we are done.
return true
}

However, the return value of strings.Split will never have length 0 because the provided separator is not empty. If provided an empty string, it will still return a slice containing a single empty string:

If s does not contain sep and sep is not empty, Split returns a slice of length 1 whose only element is s.

If sep is empty, Split splits after each UTF-8 sequence. If both s and sep are empty, Split returns an empty slice.

Maybe the condition could be replaced with if *flagBuild == "" and checked before the call to strings.Split:

 	if *flagBuild == "" { 
 		// If the value of flagBuild is empty then we are done. 
 		return true 
 	} 
 	args := strings.Split(*flagBuild, " ") 

CompileDaemon is not installing on LinuxMint Machines

u@u-pc:~/Documents/Proyectos/GoApps$ go get github.com/githubnemo/CompileDaemon

cd /home/u/go/src/golang.org/x/sys; git pull --ff-only

fatal: unable to open .git/objects/pack/tmp_pack_3iLUeQ: No such file or directory
fatal: index-pack failed
package golang.org/x/sys/unix: exit status 1

Issuing a `touch` on a file rebuilds the binary 2 times in a row

I have something like:

CompileDaemon -build="go build -o bin/darwin-amd64/x x/x.go" -command="./bin/darwin-amd64/x" -pattern=".+\.go$"

If I do a simple touch x.go the binary gets compiled twice...

EDIT: Actually, starting it simply like this does the same problem:

CompileDaemon --exclude-dir=vendor

multiple build commands

It would be great if multiple build commands could be run when file changes are detected:

1. docker build -t
2. docker-compose down
3. docker-compose up

Use CompileDaemon with go generate?

I'm trying to use CompileDaemon with go generate, but have not been successful. I am running two instances of CompileDaemon to try accomplishing this. One instances watches the source files, which are .sql, and runs go generate when they change. The other watches all .go source files and runs go build. I believe my flags are set up so that the two are watching mutually exclusive files:

#!/bin/sh

CompileDaemon -build="go generate ./..."
  -exclude="*.go"
  -include="*.sql"
  -pattern=".+\.sql$" &
CompileDaemon -build="go build -o /opt/bin/service"
  -exclude="*.sql"
  -include="*.go"
  -pattern=".+\.go$" &

However, when I run this script, CompileDaemon gets stuck in an infinite loop. Is CompileDaemon incompatible with go generate?

Change events not triggered in Docker after a while

I have a local docker-compose setup with 10+ services, where each of them is built and run by CompileDaemon. Each service's local go folder is mounted as a volume to allow the developers at my company to make changes and CompileDaemon takes care of restarting the go server when any source file is changed.

Expected Behavior

All the services should restart after a file has changed

Problem

After several restarts with 10+ services, restarts with CompileDaemon stops working without any errors and I have to manually restart the container or restart the docker daemon for the notify events to work again.

Environement

MacOS Catalina 10.15.2 (19C57)
Docker Desktop 2.2.0.3 (42716)
Engine Version 19.03.5
Compose Version 1.25.4

Example Dockerfile Entrypoint

ENTRYPOINT CompileDaemon \
    --build="go build -o my_service" \
    -exclude-dir=.git -exclude=".#*" \
    --command="./my_service"

Example Folder Mounting in Docker Compose

  my_service:
    build:
      context: .
      dockerfile: ./my_service.Dockerfile
    volumes:
      - $GOPATH/src/bitbucket.org/xxx/my_service:/go/src/bitbucket.org/xxx/my_service

Suggested Solution

If, after a thorough research we find that the problem is deeper then a few config files, maybe we can write a polling mechanism and watch for changes ourselves and ditch the inotify features. It is not the best solution but it will be a nice workaround if people just want things to work.

CompileDaemon not found

I get the error "CompileDaemon: not found" and I don't understand why I'm getting such error

Reload not working on OSX

I'm setting up a project in Go following this guide https://levelup.gitconnected.com/how-to-live-reload-code-for-golang-and-docker-without-third-parties-ee90721ef641 , on Linux it works fine. Using it from mac when I change a file from my editor, the file into the container change but CompileDaemon doesn't recognise the change and doesn't rebuild.
If I enter the container and save the changed file, CompileDaemon rebuild.

DOCKER FILE

FROM golang:latest

WORKDIR /go/src

DockerCompose

version: '3'
services:
  app:
    build:
      context: .
    volumes:
      - ".:/go/"
    container_name: golang_app
    command: bash -c "go get github.com/githubnemo/CompileDaemon && CompileDaemon -command="./app""
    ports:
      - "8080:8080"
    tty: true
    depends_on:
      - db

VERSIONs

OSX Catalina 10.15.2
Docker version 19.03.5 ( Using Docker Desktop application)

Cannot seem to kill the process properly

I'm obviously missing something, but I can't seem to catch the SIGTERM signal and gracefully terminate the running server.

package main

import (
	"context"
	"fmt"
	"log"
	"net/http"
	"os"
	"os/signal"
	"sync"
	"syscall"

	"github.com/gorilla/mux"
)

func main() {
	log.Println("Starting HTTP server on port", os.Getenv("PORT"))

	httpServerExitDone := &sync.WaitGroup{}

	httpServerExitDone.Add(1)
	srv := startHTTPServer(httpServerExitDone)

	c := make(chan os.Signal, 1)
	signal.Notify(c,
		syscall.SIGHUP,
		syscall.SIGINT,
		syscall.SIGTERM,
		syscall.SIGQUIT)

	go func() {
		<-c
		fmt.Println("\r- SIG sent to terminate")
		if err := srv.Shutdown(context.TODO()); err != nil {
			panic(err)
		}
	}()

	httpServerExitDone.Wait()
	log.Printf("main: done. exiting")
}

func startHTTPServer(wg *sync.WaitGroup) *http.Server {
	r := mux.NewRouter()
	srv := &http.Server{Addr: ":" + os.Getenv("PORT"), Handler: r}

	r.Handle("/", http.FileServer(http.Dir("./public")))

	go func() {
		defer wg.Done()

		if err := srv.ListenAndServe(); err != http.ErrServerClosed {
			log.Fatalf("ListenAndServe(): %v", err)
		}
	}()

	return srv
}

Results in:

2021/06/30 23:04:08 Gracefully stopping the current process..
2021/06/30 23:04:08 Restarting the given command.
2021/06/30 23:04:08 stderr: 2021/06/30 23:04:08 Starting HTTP server on port 3000
2021/06/30 23:04:08 stderr: 2021/06/30 23:04:08 ListenAndServe(): listen tcp :3000: bind: address already in use
2021/06/30 23:04:08 stderr: exit status 1

Goal of project

I was attempting to make this fit an existing project that currently used reflex to watch for changes and Makefile targets after using this on some personal projects and loving the simplicity, and I realized that I wanted to perform different actions if different sets of files changed.

Example:
*.tmpl - go generate path/views/templates which executes go-bindata for those templates
*.scss - go generate path/views/styles which executes sass->css compilation, then go-bindata for the CSS

Is it a goal of the project to support this type of conditional targeting? Reading the README, I'd lean towards no, but wanted to check.

Docker + Go 1.18 = /bin/sh: CompileDaemon: not found

It seems that it stopped working since the update of Go 1.18, the error is /bin/sh: CompileDaemon: not found
It works when I get Go image 1.17.

Here is my Dockerfile:

FROM golang:alpine

WORKDIR /app

COPY ./ /app

RUN go mod download

RUN go get github.com/githubnemo/CompileDaemon

ENTRY

POINT CompileDaemon --build="go build -o /app/.bin/api-admin ./cmd/admin" --command=./.bin/api-admin

Thanks

Add a tag for the most recent version

It would be great to have a newer tag than 1.1.0 in the repo, so that go get does also download the newer version.

This would enable people to use -run-dir=/foo/bar/baz

filepath.Walk():bad file descriptor

I successfully ran CompileDaemon a month ago when I downloaded it, but now whenever I try to run it I get:

filepath.Walk():bad file descriptor

I've tried deleting the src and bin files for CompileDaemon and running go get "github.com/githubnemo/CompileDaemon", but it didn't change anything.

I'm on a 2017 Macbook Pro.

go get doesn't not pull master branch with polling changes

Hi there,

For ages I was trying to work out why the -polling option was causing this to crash out in docker.

I was using this docker file:


FROM golang:latest
EXPOSE 80

WORKDIR /usr/src/app/go-api

COPY . /usr/src/app/go-api

RUN go mod download

RUN go get github.com/githubnemo/CompileDaemon
RUN GO111MODULE=on
# RUN CompileDaemon
ENTRYPOINT CompileDaemon -build="go build main.go" -directory="." -polling -command=./main 

To which it ouputted the full list of options - not including -polling

" flag provided but not defined: -polling"

To fix this, I added @master to the go get command :


FROM golang:latest
EXPOSE 80

WORKDIR /usr/src/app/go-api

COPY . /usr/src/app/go-api

RUN go mod download

RUN go get github.com/githubnemo/CompileDaemon@master
RUN GO111MODULE=on
# RUN CompileDaemon
ENTRYPOINT CompileDaemon -build="go build main.go" -directory="." -polling -command=./main 

This now works!

This is an amazing project and I am very grateful for it - I just thought that this may come up for someone else!

I'm not sure why go get is behaving like this, but I assume it is a bug.

Full code example:

main.go

package main

import (
	"net/http"

	"github.com/labstack/echo/v4"
)

func main() {
	e := echo.New()
	e.GET("/", func(c echo.Context) error {
		return c.String(http.StatusOK, "Hello, dude!")
	})
	e.GET("/2", func(c echo.Context) error {
		return c.String(http.StatusOK, "Hello, my friend, again!")
	})

	e.Logger.Fatal(e.Start(":80"))
}

Dockerfile


FROM golang:latest
EXPOSE 80

WORKDIR /usr/src/app/go-api

COPY . /usr/src/app/go-api

RUN go mod download

RUN go get github.com/githubnemo/CompileDaemon
RUN GO111MODULE=on # not sure if needed
ENTRYPOINT CompileDaemon -build="go build main.go" -directory="." -polling -command=./main 

docker-compose.yml

services:
  go-api:
    build:
      context: .
    ports:
      - "8081:80"
    container_name: go-api
    tty: true
    volumes:
      - ./:/usr/src/app/go-api
    

Docker - File Changes not being Acknowledged

Hey! - I'm making a little simple API And I've been trying to get CompuleDaemon to see any file changes and rebuild with docker. Any changes I make doesn't get reflected on my endpoints. Could I have some help/pointers?

File Structure:

- api
-- go.mod
-- go.sum
-- main.go 
-- controllers
--- users-controller.go 

DockerFile:

# syntax=docker/dockerfile:1

FROM golang:latest
RUN apt-get install git
EXPOSE 8080
WORKDIR /go/src/app
COPY /api .
RUN go mod download -x
RUN ["go", "install", "github.com/githubnemo/CompileDaemon@latest"]
ENTRYPOINT CompileDaemon -build="go build main.go" -command="./main -my-options"

Restart the program if it fails

Sometimes a running program fails because of the panic. Because CompileDaemon keeps running it is hard to notice that (except for the panic stack trace). I think it would be best if CompileDaemon would just restart the program, with some message (like, "program terminated, restarting"). Probably as opt-in CLI flag.

Restarting app that runs continously

Hi, this is a cool project.

I have written a simple web server, and Im using this to monitor for code changes. Im using it like so:

./CompileDaemon -directory=/linked -command=./linked

It starts up fine, however when I change the code, it doesn't re build. I suspect its because /linked/linked is a web server and never stops, but when I read your documentation, it mentions that CompileDaemon will kill the app and restart it. Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.