Skip to content

Commit

Permalink
Merge pull request #51 from Layr-Labs/jac/container
Browse files Browse the repository at this point in the history
chore: reduce build artifact to 117Mb
  • Loading branch information
seanmcgary authored Sep 16, 2024
2 parents 7b28653 + bb12f0b commit 67f3ff5
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 23 deletions.
37 changes: 37 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM golang:1.22-bullseye

ARG TARGETARCH

RUN export DEBIAN_FRONTEND=noninteractive && \
apt update && \
apt install -y -q --no-install-recommends \
build-essential gcc musl-dev linux-headers-${TARGETARCH} && \
apt clean && \
rm -rf /var/lib/apt/lists/*

RUN useradd --create-home -s /bin/bash gobuild
RUN usermod -a -G sudo gobuild
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

ARG PROJECT=go-sidecar
RUN mkdir -p /workspaces/${PROJECT}
WORKDIR /workspaces/${PROJECT}
COPY --chown=gobuild:gobuild . .

# system and linux dependencies
RUN make deps-linux
RUN chown -R gobuild:gobuild /go

# local dependencies
ENV USER=gobuild
ENV GOBIN=/go/bin
ENV PATH=$PATH:${GOBIN}
USER gobuild

RUN git config --global --add safe.directory /workspaces/${PROJECT}

RUN make yamlfmt
RUN make fmtcheck
RUN make vet
RUN make lint
RUN make test
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Sets the run context to one level up instead of the .devcontainer folder.
"context": "..",
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerfile": "../Dockerfile"
"dockerfile": "./Dockerfile"
},
"customizations": {
"vscode": {
Expand Down
38 changes: 16 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
FROM golang:1.22-bullseye AS build
FROM golang:1.22-bullseye AS builder

RUN apt-get update
RUN apt-get install -y make
ARG TARGETARCH

RUN useradd --create-home -s /bin/bash gobuild
RUN usermod -a -G sudo gobuild
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
RUN export DEBIAN_FRONTEND=noninteractive && \
apt update && \
apt install -y -q --no-install-recommends \
build-essential gcc musl-dev linux-headers-${TARGETARCH} && \
apt clean && \
rm -rf /var/lib/apt/lists/*

ARG PROJECT=go-sidecar
RUN mkdir -p /workspaces/${PROJECT}
WORKDIR /workspaces/${PROJECT}
COPY --chown=gobuild:gobuild . .
WORKDIR /build

COPY . .

# system and linux dependencies
RUN make deps-linux
RUN chown -R gobuild:gobuild /go

# local dependencies
ENV USER=gobuild
ENV GOBIN=/go/bin
ENV PATH=$PATH:${GOBIN}
USER gobuild
RUN make build

FROM debian:stable-slim

RUN git config --global --add safe.directory /workspaces/${PROJECT}
COPY --from=builder /build/bin/cmd/sidecar /usr/local/bin/sidecar

RUN make yamlfmt
RUN make fmtcheck
RUN make vet
RUN make lint
RUN make test
ENTRYPOINT ["/usr/local/bin/sidecar"]
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ clean:
.PHONY: build/cmd/sidecar
build/cmd/sidecar:
go build -ldflags="-s -w" -o bin/cmd/sidecar cmd/sidecar/main.go
strip bin/cmd/sidecar

.PHONY: build
build: build/cmd/sidecar
Expand Down

0 comments on commit 67f3ff5

Please sign in to comment.