diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ddefd13 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +# Ignore everything +* + +# But these files... +!**/go.** +!**.go diff --git a/Dockerfile b/Dockerfile index 4cffec0..071ec62 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,12 @@ -FROM golang:alpine3.15 +# syntax = docker/dockerfile:latest +FROM golang as build +WORKDIR /app +COPY . . +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + go mod tidy; \ + CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o lazytainer ./... -WORKDIR /root/ -COPY ./go.mod ./go.sum ./ -RUN go mod download -COPY ./lazytainer.go . -RUN go build lazytainer.go - -FROM alpine:latest -WORKDIR /root/ -COPY --from=0 /root/lazytainer ./ - -CMD ["./lazytainer"] \ No newline at end of file +FROM scratch +COPY --from=build /app/lazytainer /usr/local/bin/lazytainer +ENTRYPOINT ["/usr/local/bin/lazytainer"] diff --git a/README.md b/README.md index 8f3cd4a..9e07b58 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,18 @@ # Lazytainer - Lazy Load Containers -Putting your containers to sleep +Putting your containers to sleep [![Docker](https://github.com/vmorganp/Lazytainer/actions/workflows/docker-publish.yml/badge.svg)](https://github.com/vmorganp/Lazytainer/actions/workflows/docker-publish.yml) --- ## How it works -Monitors network traffic for active connections and recieved packets -If traffic looks to be idle, container stops +Monitors network traffic for active connections and recieved packets +If traffic looks to be idle, container stops If traffic is incoming to stopped container, container starts ## Want to test it? ``` $ git clone https://github.com/vmorganp/Lazytainer $ cd Lazytainer -$ docker-compose up +$ docker-compose up ``` ## Or put in your docker-compose.yaml @@ -21,10 +21,10 @@ $ docker-compose up container_name: lazytainer image: ghcr.io/vmorganp/lazytainer:master environment: - - PORT=81 # comma separated list of ports...or just the one + - PORT=81 # comma separated list of ports...or just the one - LABEL=lazytainer # value of lazytainer.marker for other containers that lazytainer checks # - TIMEOUT=30 # OPTIONAL number of seconds to let container idle - # - MINPACKETTHRESH=10 # OPTIONAL number of packets that must be recieved to keepalive/start container + # - MINPACKETTHRESH=10 # OPTIONAL number of packets that must be recieved to keepalive/start container # - POLLRATE=1 # OPTIONAL number of seconds to sleep between polls # - VERBOSE=true # probably set this to false unless you're debugging or doing the initial demo ports: @@ -38,7 +38,7 @@ $ docker-compose up # configuring service ports is container specific. Look up how to do this on your service of choice command: --port 81 # make this run on the port passed through on lazytainer network_mode: service:lazytainer - depends_on: + depends_on: - lazytainer # wait for lazytainer to start before starting labels: - "lazytainer.marker=lazytainer" # required label to make it work diff --git a/docker-compose.yaml b/docker-compose.yaml index a162f02..beec406 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -4,10 +4,10 @@ services: container_name: lazytainer image: ghcr.io/vmorganp/lazytainer:master environment: - - PORT=81,82 # comma separated list of ports...or just the one + - PORT=81,82 # comma separated list of ports...or just the one - LABEL=lazytainer # value of lazytainer.marker for other containers that lazytainer checks - TIMEOUT=30 # OPTIONAL number of seconds to let container idle - - MINPACKETTHRESH=10 # OPTIONAL number of packets that must be recieved to keepalive/start container + - MINPACKETTHRESH=10 # OPTIONAL number of packets that must be recieved to keepalive/start container - POLLRATE=1 # OPTIONAL number of seconds to sleep between polls - VERBOSE=true # probably set this to false unless you're debugging or doing the initial demo ports: @@ -21,7 +21,7 @@ services: image: containous/whoami command: --port 81 network_mode: service:lazytainer - depends_on: + depends_on: - lazytainer labels: - "lazytainer.marker=lazytainer" @@ -32,7 +32,7 @@ services: image: containous/whoami command: --port 82 network_mode: service:lazytainer - depends_on: + depends_on: - lazytainer labels: - "lazytainer.marker=lazytainer"