Skip to content

Commit

Permalink
[utils] staged building with custom versions
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Sep 29, 2023
1 parent 30928b9 commit e47837e
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 28 deletions.
2 changes: 1 addition & 1 deletion py/build_mypyc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cd $(dirname $0)
source py_env.sh
rm -rf rbmp
cp -r src rbmp
sed -i '' 's/from src./from rbmp./' rbmp/*.py
sed -i'' 's/from src./from rbmp./' rbmp/*.py
mypyc rbmp

cat >rosettaboy-mypyc <<EOD
Expand Down
1 change: 1 addition & 0 deletions rs/build_lto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ set -eu

cd $(dirname $0)
cargo build --profile release-lto
rm -f ./rosettaboy-lto
mv ./target/release-lto/rosettaboy-rs ./rosettaboy-lto
131 changes: 104 additions & 27 deletions utils/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,65 +1,142 @@
ARG PHP_VERSION=8.2
ARG PYTHON_VERSION=3.11
ARG RUST_VERSION=1.67.1
ARG ZIG_VERSION=0.11.0-dev.1606+3c2a43fdc
# TODO: nim 2.0.0
ARG GO_VERSION=1.21.1
ARG NIM_VERSION=1.6.6
ARG PHP_VERSION=8.2.10
ARG PYTHON_VERSION=3.11.5
ARG RUST_VERSION=1.72.0
ARG ZIG_VERSION=0.11.0

FROM debian:unstable

#######################################################################
# Foundations

FROM debian:unstable AS base-builder
# Install foundations-which-rarely-change up-front so we can cache them,
# and then install language-specific things on top
USER root
RUN apt update && apt install -y \
build-essential linux-perf valgrind vim git libsdl2-dev wget
build-essential linux-perf valgrind vim git mercurial libsdl2-dev wget curl

# Configure developer environment
ARG USER_ID
ARG GROUP_ID
RUN addgroup --gid $GROUP_ID dev || true
RUN adduser --disabled-password --gecos '' --uid $USER_ID --gid $GROUP_ID dev

# Install C++ tools
USER root
RUN apt update && apt install -y cmake clang-format-14 libfmt-dev

# Install Go tools
USER root
RUN apt update && apt install -y golang
#######################################################################
# Go

# Install Nim tools
USER root
RUN apt update && apt install -y nim
FROM base-builder AS go-builder
ARG GO_VERSION
USER dev
RUN wget https://go.dev/dl/go${GO_VERSION}.linux-$(dpkg --print-architecture).tar.gz -O - | tar -xz -C /tmp
RUN mv /tmp/go /home/dev/.go
ENV PATH="/home/dev/.go/bin:$PATH"


#######################################################################
# Nim

FROM base-builder AS nim-builder
ARG NIM_VERSION
USER dev
ENV CHOOSENIM_CHOOSE_VERSION=${NIM_VERSION}
RUN curl https://nim-lang.org/choosenim/init.sh -sSf | sh -s -- -y
ENV PATH="/home/dev/.nimble/bin:$PATH"
RUN nimble refresh

# Install PHP tools

#######################################################################
# PHP

FROM base-builder AS php-builder
ARG PHP_VERSION
USER root
RUN apt update && apt install -y php${PHP_VERSION}-cli php${PHP_VERSION}-dev
RUN apt-get install -y libxml2-dev libsqlite3-dev libssl-dev autoconf
USER dev
RUN wget https://www.php.net/distributions/php-${PHP_VERSION}.tar.gz -O - | tar -xz -C /tmp
RUN cd /tmp/php-${PHP_VERSION} && ./configure --prefix=/home/dev/.php --with-openssl && make -j install
ENV PATH="/home/dev/.php/bin:$PATH"
RUN curl https://getcomposer.org/installer | php -- --quiet --install-dir=/home/dev/.php/bin/ --filename=composer
RUN git clone https://github.com/Ponup/php-sdl ~/php-sdl && \
cd ~/php-sdl && phpize && ./configure && make
cd ~/php-sdl && phpize && ./configure && make -j

# Install Python tools

#######################################################################
# Python

FROM base-builder AS py-builder
ARG PYTHON_VERSION
USER root
RUN apt update && apt install -y python${PYTHON_VERSION} python${PYTHON_VERSION}-venv python${PYTHON_VERSION}-dev black
RUN mkdir -p /home/dev/.local/bin && ln -s /usr/bin/python${PYTHON_VERSION} /home/dev/.local/bin/python3
ENV PATH="/home/dev/.local/bin:$PATH"
RUN apt-get install -y --no-install-recommends \
make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev \
libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev \
libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
RUN apt-get install -y mecab-ipadic-utf8
USER dev
RUN git clone --depth=1 https://github.com/yyuu/pyenv /home/dev/.pyenv
ENV PYENV_ROOT="/home/dev/.pyenv"
ENV PATH="/home/dev/.pyenv/shims:/home/dev/.pyenv/bin:$PATH"
RUN pyenv install ${PYTHON_VERSION}
RUN pyenv global ${PYTHON_VERSION}
RUN pyenv rehash

# Install Rust tools

#######################################################################
# Rust

FROM base-builder AS rs-builder
ARG RUST_VERSION
USER dev
RUN wget -qO - https://sh.rustup.rs | sh -s -- --default-toolchain ${RUST_VERSION} -y
ENV PATH="/home/dev/.cargo/bin:$PATH"
RUN cargo search foo

# Install Zig tools

#######################################################################
# Zig

FROM base-builder AS zig-builder
ARG ZIG_VERSION
USER dev

# RUN wget https://ziglang.org/download/${ZIG_VERSION}/zig-linux-$(uname -m)-${ZIG_VERSION}.tar.xz -O /tmp/zig.tar.xz && \
RUN wget https://ziglang.org/builds/zig-linux-$(uname -m)-${ZIG_VERSION}.tar.xz -O /tmp/zig.tar.xz && \
mkdir ~/.zig && tar --strip-components=1 -C ~/.zig -xf /tmp/zig.tar.xz && rm -f /tmp/zig.tar.gz


#######################################################################
# Final image

FROM base-builder AS final

# Install C/C++ tools
USER root
RUN apt update && apt install -y cmake clang clang-format-14 libfmt-dev

# Install Go tools
COPY --from=go-builder --chown=dev:dev /home/dev/.go /home/dev/.go
ENV PATH="/home/dev/.go/bin:$PATH"

# Install Nim tools
COPY --from=nim-builder --chown=dev:dev /home/dev/.choosenim /home/dev/.choosenim
COPY --from=nim-builder --chown=dev:dev /home/dev/.nimble /home/dev/.nimble
ENV PATH="/home/dev/.nimble/bin:$PATH"

# Install PHP tools
COPY --from=php-builder --chown=dev:dev /home/dev/.php /home/dev/.php
ENV PATH="/home/dev/.php/bin:$PATH"

# Install Python tools
COPY --from=py-builder --chown=dev:dev /home/dev/.pyenv /home/dev/.pyenv
ENV PYENV_ROOT="/home/dev/.pyenv"
ENV PATH="/home/dev/.pyenv/shims:/home/dev/.pyenv/bin:$PATH"

# Install Rust tools
COPY --from=rs-builder --chown=dev:dev /home/dev/.rustup /home/dev/.rustup
COPY --from=rs-builder --chown=dev:dev /home/dev/.cargo /home/dev/.cargo
ENV PATH="/home/dev/.cargo/bin:$PATH"

# Install Zig tools
COPY --from=zig-builder --chown=dev:dev /home/dev/.zig /home/dev/.zig
ENV PATH="/home/dev/.zig:$PATH"

# Get ready to go
Expand Down

0 comments on commit e47837e

Please sign in to comment.