Skip to content

Commit

Permalink
dockerfile: Use CGO_ENABLED=0 when building binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
hjpotter92 committed Jan 23, 2023
1 parent d3279c5 commit ecaf2a5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ concurrency:

jobs:
build:
name: Build and publish docker images
name: Build and publish ${{ matrix.build.name }} docker images
runs-on: ubuntu-latest
permissions:
packages: write
Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:
platforms: linux/amd64
push: true
build-args: |
version=${{ github.ref_type == 'tag' && github.ref_name || github.sha }}
version=${{ (github.ref_type == 'tag' && github.ref_name) || (github.event.pull_request.head.sha || github.sha) }}
tags: ${{ steps.meta.outputs.tags }}
file: 'docker/${{ matrix.build.file }}'
labels: ${{ steps.meta.outputs.labels }}
Expand Down
16 changes: 8 additions & 8 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ COPY . .

ARG version

RUN go build -ldflags="-X 'github.com/livepeer/stream-tester/model.Version=$version' -X 'github.com/livepeer/stream-tester/model.IProduction=true'" -tags h264 cmd/streamtester/streamtester.go
RUN parallel -q go build -ldflags="-X 'github.com/livepeer/stream-tester/model.Version=$version' -X 'github.com/livepeer/stream-tester/model.IProduction=true'" cmd/{}/{}.go ::: testdriver mist-api-connector loadtester stream-monitor recordtester
RUN CGO_ENABLED=0 go build -ldflags="-X 'github.com/livepeer/stream-tester/model.Version=$version' -X 'github.com/livepeer/stream-tester/model.IProduction=true'" -tags h264 cmd/streamtester/streamtester.go \
&& parallel -q go build -ldflags="-X 'github.com/livepeer/stream-tester/model.Version=$version' -X 'github.com/livepeer/stream-tester/model.IProduction=true'" cmd/{}/{}.go ::: testdriver mist-api-connector loadtester stream-monitor recordtester

FROM alpine:3.15.4

Expand All @@ -28,11 +28,11 @@ WORKDIR /root
COPY --from=builder /root/*.mp4 ./
COPY --from=builder /root/official_test_source_2s_keys_24pfs_30s_hls official_test_source_2s_keys_24pfs_30s_hls

COPY --from=builder /root/streamtester /usr/local/bin/streamtester
COPY --from=builder /root/testdriver /usr/local/bin/testdriver
COPY --from=builder /root/mist-api-connector /usr/local/bin/mist-api-connector
COPY --from=builder /root/loadtester /usr/local/bin/loadtester
COPY --from=builder /root/stream-monitor /usr/local/bin/stream-monitor
COPY --from=builder /root/recordtester /usr/local/bin/recordtester
COPY --from=builder /root/streamtester \
/root/testdriver \
/root/mist-api-connector \
/root/loadtester \
/root/stream-monitor \
/root/recordtester /usr/local/bin/

RUN for b in testdriver mist-api-connector loadtester stream-monitor recordtester; do ln -s /usr/local/bin/$b ./$b; done
6 changes: 3 additions & 3 deletions docker/Dockerfile.orch-tester
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ RUN go mod download

COPY . .

RUN go build -ldflags="-X 'github.com/livepeer/stream-tester/model.Version=$version' -X 'github.com/livepeer/stream-tester/model.IProduction=true'" \
ARG version

RUN CGO_ENABLED=0 go build -ldflags="-X 'github.com/livepeer/stream-tester/model.Version=$version' -X 'github.com/livepeer/stream-tester/model.IProduction=true'" \
-tags mainnet \
cmd/orch-tester/orch_tester.go cmd/orch-tester/broadcaster_metrics.go

Expand All @@ -31,6 +33,4 @@ WORKDIR /root
COPY --from=builder /root/official_test_source_2s_keys_24pfs_30s_hls official_test_source_2s_keys_24pfs_30s_hls
COPY --from=builder /root/orch_tester /usr/local/bin/orch_tester

RUN ln -s /usr/local/bin/orch_tester ./

ENTRYPOINT ["/usr/local/bin/orch_tester"]
7 changes: 4 additions & 3 deletions docker/Dockerfile.record-tester
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ ENV GOARCH="${TARGETARCH}"
WORKDIR /root

ENV GOFLAGS "-mod=readonly"
ARG version

COPY go.mod go.sum ./

RUN go mod download

ARG version

COPY . .

RUN go build -ldflags="-X 'github.com/livepeer/stream-tester/model.Version=$version' -X 'github.com/livepeer/stream-tester/model.IProduction=true'" cmd/streamtester/streamtester.go
RUN go build -ldflags="-X 'github.com/livepeer/stream-tester/model.Version=$version' -X 'github.com/livepeer/stream-tester/model.IProduction=true'" cmd/recordtester/recordtester.go
RUN CGO_ENABLED=0 go build -ldflags="-X 'github.com/livepeer/stream-tester/model.Version=$version' -X 'github.com/livepeer/stream-tester/model.IProduction=true'" cmd/streamtester/streamtester.go \
&& CGO_ENABLED=0 go build -ldflags="-X 'github.com/livepeer/stream-tester/model.Version=$version' -X 'github.com/livepeer/stream-tester/model.IProduction=true'" cmd/recordtester/recordtester.go

FROM --platform=$TARGETPLATFORM debian:stretch-slim

Expand Down

0 comments on commit ecaf2a5

Please sign in to comment.