Skip to content

Instantly share code, notes, and snippets.

@matti
Last active November 2, 2022 09:19
Show Gist options
  • Save matti/5c0ef30ab25fd031847705ec9f5bda43 to your computer and use it in GitHub Desktop.
Save matti/5c0ef30ab25fd031847705ec9f5bda43 to your computer and use it in GitHub Desktop.

Dope Dockerfile

Copy all from a docker image to a path

COPY --from=mattipaksula/reflex:sha-0238059 /* /usr/bin/

Bind port below 1024 without root

RUN apk add --no-cache libcap

COPY --from=mattipaksula/harderdns:sha-674b3ac /* /usr/local/bin
RUN setcap CAP_NET_BIND_SERVICE=+eip /usr/local/bin/harderdns

# now harderdns can bind :53

Force platform

FROM --platform=linux/amd64 ubuntu:20.04

Persist shell history between containers

Write history to the disk immediately

ENV PROMPT_COMMAND="history -a"

create the file locally (otherwise it will be a directory) with touch .bash_history and then bind mount the file:

volumes:
  - ./.bash_history:/root/.bash_history

Install deps with curl

create a temporary directory, extract all, move needed and delete rest

RUN mkdir /ghjk && cd /ghjk \
  && curl -Lsf -O https://github.com/cloudflare/cloudflare-go/releases/download/v0.36.0/flarectl_0.36.0_linux_amd64.tar.xz \
  && tar -xvof flarectl_0.36.0_linux_amd64.tar.xz \
  && mv flarectl /usr/local/bin \
  && rm -rf /ghjk

Install deps with asdf

FROM --platform=linux/amd64 ubuntu:20.04
ENV PATH="/root/.asdf/shims/:/asdf/bin:${PATH}"

RUN export DEBIAN_FRONTEND=noninteractive; apt-get update && apt-get install -y --no-install-recommends \
  ca-certificates \
  git curl

RUN git clone https://github.com/asdf-vm/asdf.git /asdf --branch v0.9.0

WORKDIR /app

COPY .tool-versions .

RUN asdf plugin add eksctl
RUN asdf plugin add kubectl
RUN asdf plugin add jq
RUN asdf plugin add helm
RUN asdf install

Use previous image as a cache to speed up

FROM --platform=linux/amd64 user/image as cache
FROM --platform=linux/amd64 ruby:3.0.0-alpine

WORKDIR /app

COPY --from=cache /usr/local/bundle/ /usr/local/bundle/
COPY Gemfile .

# this will still run, but gems are already installed
RUN apk add --no-cache --virtual .gem-deps \
  build-base \
  && gem install bundler -v 2.1.4 \
  && bundle install --jobs $(nproc) \
  && bundle clean --force \
  && apk del .gem-deps

Download correct architecture

RUN [ "$(uname -m)" = "aarch64" ] && arch=arm64 || arch=amd64 \
  && mkdir /ghjk && cd /ghjk \
  && curl -Lsf -O https://go.dev/dl/go1.19.1.linux-${arch}.tar.gz \
  && tar -C /usr/local -xzf go1.19.1.linux-${arch}.tar.gz \
  && rm -rf /ghjk
WORKDIR /app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment