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

fix(dockerfile): optimized Dockerfile #3281

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

No0key
Copy link

@No0key No0key commented Sep 12, 2024

Hello!

This PR optimizes the Dockerfile.

Changes include:

  • Combined RUN commands to reduce the number of layers
  • Cached Go dependencies to speed up build times
  • Cleaned up unnecessary apt files to reduce image size
  • Consolidated user creation and permission setting commands

Category: refactor

Reduced image size from 370MB to 302MB

Dockerfile Outdated
@@ -18,33 +26,41 @@

# Copy final binary into light stage.
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y ca-certificates wget fio
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates wget fio \

Check notice

Code scanning / SonarCloud

Arguments in long RUN instructions should be sorted Low

Sort these package names alphanumerically. See more on SonarCloud
Copy link

sonarcloud bot commented Sep 12, 2024

@No0key No0key changed the title fix(dockerfile): optimized dockerfile, removed additional docker layers fix(dockerfile): optimized Dockerfile Sep 12, 2024
Comment on lines +10 to +11
COPY go.mod go.sum ./
RUN go mod download
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary as go build will download the dependencies.

# Install dependencies
RUN apt-get update && apt-get install -y build-essential git
RUN apt-get update && apt-get install -y --no-install-recommends build-essential git \
&& rm -rf /var/lib/apt/lists/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary, as this is multi-stage build and the image from the first stage is not used in the final image.

Comment on lines +51 to +52
&& mkdir -p "/opt/$USER" \
&& chown "$USER" "/opt/$USER"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary, as the adduser command already created this directory, see --home "/opt/$USER". Its owner is also the said user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants