Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: reduce build artifact to 117Mb #51

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading