fix docker build of unit/broadcast

- build go project in container
- deploy in smaller alpine container
- fix docker-compose
- add Makefile to build docker container
This commit is contained in:
bretello 2020-10-22 18:54:37 +02:00
parent b055a9200e
commit 8fa584775f
7 changed files with 84 additions and 59 deletions

View File

@ -1,23 +0,0 @@
FROM golang:1.15 AS builder
ENV DEBIAN_FRONTEND=noninteractive
COPY ./broadcast /broadcast
WORKDIR /broadcast
RUN apt-get update \
&& apt-get install -y libmp3lame-dev \
&& go get -u ./... \
&& rm -rf /var/lib/apt/lists/*
FROM debian:stable
ENV DEBIAN_FRONTEND=noninteractive
COPY --from=builder /go/bin/broadcast /srv/
COPY ./entrypoint.sh /entrypoint.sh
WORKDIR /srv
RUN apt-get update \
&& apt-get install -y libmp3lame0 \
&& rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["/entrypoint.sh"]

24
broadcast/Dockerfile Normal file
View File

@ -0,0 +1,24 @@
FROM golang:1.15 AS builder
ENV DEBIAN_FRONTEND=noninteractive
COPY ./go.* /broadcast/
COPY /*.go /broadcast/
WORKDIR /broadcast
RUN apt-get update \
&& apt-get install -y libmp3lame-dev\
&& go get -u ./... \
&& rm -rf /var/lib/apt/lists/*
# RUN env GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o /broadcast/broadcast
RUN env go build -o /broadcast/broadcast
# RUN go build -o /broadcast/broadcast
# FROM alpine:latest
FROM golang:1.15
WORKDIR /srv
COPY --from=builder /broadcast/broadcast /srv/broadcast
CMD /srv/broadcast

4
broadcast/Makefile Normal file
View File

@ -0,0 +1,4 @@
all: docker
docker:
docker build -t unit/broadcast .

View File

@ -3,6 +3,6 @@ module git.abbiamoundominio.org/unit/broadcast
go 1.15
require (
github.com/sunicy/go-lame v0.0.0-20200422031049-1c192eaafa39
github.com/golang/protobuf v1.4.2 // indirect
layeh.com/gumble v0.0.0-20200818122324-146f9205029b
)

View File

@ -1,8 +1,26 @@
github.com/dchote/go-openal v0.0.0-20171116030048-f4a9a141d372/go.mod h1:74z+CYu2/mx4N+mcIS/rsvfAxBPBV9uv8zRAnwyFkdI=
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/sunicy/go-lame v0.0.0-20200422031049-1c192eaafa39 h1:P/6L4pZMkHutxyefALLAiXCPkcD+5NcvJRGayZmtBmY=
github.com/sunicy/go-lame v0.0.0-20200422031049-1c192eaafa39/go.mod h1:H5mJP3sFKpUGaeckgSaMVXcTgnSgImhx54qyQXbpTVY=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
layeh.com/gopus v0.0.0-20161224163843-0ebf989153aa h1:WNU4LYsgD2UHxgKgB36mL6iMAMOvr127alafSlgBbiA=
layeh.com/gopus v0.0.0-20161224163843-0ebf989153aa/go.mod h1:AOef7vHz0+v4sWwJnr0jSyHiX/1NgsMoaxl+rEPz/I0=
layeh.com/gumble v0.0.0-20200818122324-146f9205029b h1:Kne6wkHqbqrygRsqs5XUNhSs84DFG5TYMeCkCbM56sY=

View File

@ -1,16 +1,16 @@
package main
import (
"io"
"os"
"time"
"crypto/tls"
"fmt"
"github.com/sunicy/go-lame"
"net"
"log"
"layeh.com/gumble/gumble"
"layeh.com/gumble/gumbleutil"
_ "layeh.com/gumble/opus" // it's a good idea to load this: botamusique crashes because of a CodecNotSupportedError EXception
@ -72,8 +72,12 @@ func main() {
l := AudioListener{name: "Eventprinter"}
config.AttachAudio(l)
client, err := gumble.DialWithDialer(&net.Dialer{}, "mumble:64738", config, &tls.Config{InsecureSkipVerify: true}) // TODO: fix cert or make it an option
mumbleServer := os.Getenv("MUMBLE_SERVER")
if len(mumbleServer) == 0 {
mumbleServer = "mumble:64738"
log.Printf("Mumble server not defined, falling back to default value: %s", mumbleServer)
}
client, err := gumble.DialWithDialer(&net.Dialer{}, mumbleServer, config, &tls.Config{InsecureSkipVerify: true}) // TODO: fix cert or make it an option
if err != nil {
panic(err)

View File

@ -1,36 +1,34 @@
version: '3'
version: "3"
services:
broadcast:
image: unit/broadcast
build: .
depends_on:
- mumble
icecast:
image: infiniteproject/icecast
ports:
- "8000:80"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000"]
interval: 30s
timeout: 1s
retries: 3
start_period: 4s
mumble:
image: coppit/mumble-server
ports:
- "64738:64738"
volumes:
- $PWD/mumble:/data
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:64738"]
interval: 30s
timeout: 1s
retries: 3
start_period: 4s
# depends_on:
# - mumble
environment:
- MUMBLE_SERVER: parla.abbiamoundominio.org:64738
# icecast:
# image: infiniteproject/icecast
# ports:
# - "8000:80"
# healthcheck:
# test: ["CMD", "curl", "-f", "http://localhost:8000"]
# interval: 30s
# timeout: 1s
# retries: 3
# start_period: 4s
# mumble:
# image: coppit/mumble-server
# ports:
# - "64738:64738"
# volumes:
# - $PWD/mumble:/data
# healthcheck:
# test: ["CMD", "curl", "-f", "http://localhost:64738"]
# interval: 30s
# timeout: 1s
# retries: 3
# start_period: 4s