From b7e958632714e244b498ee9b88755a99e6d24ed5 Mon Sep 17 00:00:00 2001 From: Kevin Cali <20154415+kevincali@users.noreply.github.com> Date: Sat, 20 Apr 2024 10:05:53 +0200 Subject: [PATCH] feat: shrink container image size --- .github/workflows/cd.yaml | 5 +++++ Dockerfile | 8 +++----- Makefile | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 7f71665..2f0ddf8 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -14,6 +14,11 @@ jobs: - name: checkout code uses: actions/checkout@v4 + - name: setup go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - name: build image run: make build-image diff --git a/Dockerfile b/Dockerfile index 9c37636..dd83704 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,5 @@ -FROM golang:alpine +FROM gcr.io/distroless/static:nonroot -COPY . . +COPY ./teamspeak-to-telegram /bin/teamspeak-to-telegram -RUN go build -o /teamspeak-to-telegram - -ENTRYPOINT ["/teamspeak-to-telegram"] +ENTRYPOINT ["teamspeak-to-telegram"] diff --git a/Makefile b/Makefile index 993e75c..4bf5ee8 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,10 @@ COMMIT_HASH := $(shell git --no-pager describe --tags --always --dirty) build-image: + CGO_ENABLED=0 go build . docker build --tag kevincali/teamspeak-to-telegram:$(COMMIT_HASH) --tag kevincali/teamspeak-to-telegram:latest . run-image: build-image - docker run --env CONFIG_PATH=config.yaml kevincali/teamspeak-to-telegram:latest + docker run --volume ./config.yaml:/config.yaml --env CONFIG_PATH=/config.yaml kevincali/teamspeak-to-telegram:latest push-image: docker push kevincali/teamspeak-to-telegram:$(COMMIT_HASH)