Skip to content

Commit

Permalink
Seperate Containerfile into two files
Browse files Browse the repository at this point in the history
  • Loading branch information
zifeitong committed Jun 11, 2024
1 parent 75ea137 commit c74c57c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 75 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/build-and-push-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: Create and push a continer image

on:
push:
branches: ['main']
branches: ['latest']

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
IMAGE_NAME: zifeitong/ubuntu-devpack

jobs:
build-and-push-image:
Expand Down Expand Up @@ -43,8 +43,7 @@ jobs:
uses: docker/[email protected]
with:
context: .
file: ./Containerfile
target: ubuntu-devpack
file: ./Containerfile.ubuntu-devpack
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down
72 changes: 1 addition & 71 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -1,74 +1,4 @@
FROM docker.io/library/ubuntu:24.04 AS builder

# Install packages needed for building packages.
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get -y install \
g++ openjdk-11-jdk-headless golang curl git libelf-dev libcap-dev && \
rm -rd /var/lib/apt/lists/*

ARG TARGETARCH
ARG BAZELISK_URL=https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-
ARG BUILDIFIER_URL=https://github.com/bazelbuild/buildtools/releases/latest/download/buildifier-linux-
ARG BUILDOZER_URL=https://github.com/bazelbuild/buildtools/releases/latest/download/buildozer-linux-

# Install bazel
RUN curl --proto '=https' --tlsv1.3 -sSfL ${BAZELISK_URL}${TARGETARCH} > bazel
RUN chmod +x bazel
RUN curl --proto '=https' --tlsv1.3 -sSfL ${BUILDIFIER_URL}${TARGETARCH} > buildifier
RUN curl --proto '=https' --tlsv1.3 -sSfL ${BUILDOZER_URL}${TARGETARCH} > buildozer

# Install copybara
RUN git clone https://github.com/google/copybara.git --depth=1
WORKDIR /copybara
RUN /bazel build //java/com/google/copybara:copybara_deploy.jar -c opt

# Install perf_data_converter
WORKDIR /
RUN git clone https://github.com/google/perf_data_converter.git --depth=1
WORKDIR /perf_data_converter
RUN /bazel build src:perf_to_profile -c opt

# Install pprof
WORKDIR /
RUN git clone https://github.com/google/pprof.git --depth=1
WORKDIR /pprof
RUN go build

FROM docker.io/library/ubuntu:24.04 as ubuntu-devpack
LABEL name="ubuntu-debpack" version="24.04"

# Remove apt configuration optimized for containers
RUN rm /etc/apt/apt.conf.d/docker-gzip-indexes /etc/apt/apt.conf.d/docker-no-languages

# Delete the default 'ubuntu' user
RUN userdel --remove ubuntu

# Install packages
COPY extra-packages /
RUN apt-get update && \
yes | /usr/local/sbin/unminimize && \
DEBIAN_FRONTEND=noninteractive apt-get -y install \
ubuntu-minimal ubuntu-standard $(grep -v '^#' extra-packages | xargs)
RUN rm /extra-packages

COPY --from=builder --chmod=755 bazel buildifier buildozer /pprof/pprof \
/perf_data_converter/bazel-bin/src/perf_to_profile \
/usr/local/bin/
COPY --from=builder \
/copybara/bazel-bin/java/com/google/copybara/copybara_deploy.jar \
/opt/copybara/
COPY --chmod=755 <<"EOF" /usr/local/bin/copybara
#!/usr/bin/env bash
exec java -jar /opt/copybara/copybara_deploy.jar "$@"
EOF

# Disable APT ESM hook.
RUN rm /etc/apt/apt.conf.d/20apt-esm-hook.conf

# Update command-not-found database
RUN apt-get update

FROM ubuntu-devpack
FROM ghcr.io/zifeitong/ubuntu-devpack:latest

# Add user
ARG USER
Expand Down
69 changes: 69 additions & 0 deletions Containerfile.ubuntu-devpack
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
FROM docker.io/library/ubuntu:24.04 AS builder

# Install packages needed for building packages.
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get -y install \
g++ openjdk-11-jdk-headless golang curl git libelf-dev libcap-dev && \
rm -rd /var/lib/apt/lists/*

ARG TARGETARCH
ARG BAZELISK_URL=https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-
ARG BUILDIFIER_URL=https://github.com/bazelbuild/buildtools/releases/latest/download/buildifier-linux-
ARG BUILDOZER_URL=https://github.com/bazelbuild/buildtools/releases/latest/download/buildozer-linux-

# Install bazel
RUN curl --proto '=https' --tlsv1.3 -sSfL ${BAZELISK_URL}${TARGETARCH} > bazel
RUN chmod +x bazel
RUN curl --proto '=https' --tlsv1.3 -sSfL ${BUILDIFIER_URL}${TARGETARCH} > buildifier
RUN curl --proto '=https' --tlsv1.3 -sSfL ${BUILDOZER_URL}${TARGETARCH} > buildozer

# Install copybara
RUN git clone https://github.com/google/copybara.git --depth=1
WORKDIR /copybara
RUN /bazel build //java/com/google/copybara:copybara_deploy.jar -c opt

# Install perf_data_converter
WORKDIR /
RUN git clone https://github.com/google/perf_data_converter.git --depth=1
WORKDIR /perf_data_converter
RUN /bazel build src:perf_to_profile -c opt

# Install pprof
WORKDIR /
RUN git clone https://github.com/google/pprof.git --depth=1
WORKDIR /pprof
RUN go build

FROM docker.io/library/ubuntu:24.04 as ubuntu-devpack
LABEL name="ubuntu-debpack" version="24.04"

# Remove apt configuration optimized for containers
RUN rm /etc/apt/apt.conf.d/docker-gzip-indexes /etc/apt/apt.conf.d/docker-no-languages

# Delete the default 'ubuntu' user
RUN userdel --remove ubuntu

# Install packages
COPY extra-packages /
RUN apt-get update && \
yes | /usr/local/sbin/unminimize && \
DEBIAN_FRONTEND=noninteractive apt-get -y install \
ubuntu-minimal ubuntu-standard $(grep -v '^#' extra-packages | xargs)
RUN rm /extra-packages

COPY --from=builder --chmod=755 bazel buildifier buildozer /pprof/pprof \
/perf_data_converter/bazel-bin/src/perf_to_profile \
/usr/local/bin/
COPY --from=builder \
/copybara/bazel-bin/java/com/google/copybara/copybara_deploy.jar \
/opt/copybara/
COPY --chmod=755 <<"EOF" /usr/local/bin/copybara
#!/usr/bin/env bash
exec java -jar /opt/copybara/copybara_deploy.jar "$@"
EOF

# Disable APT ESM hook.
RUN rm /etc/apt/apt.conf.d/20apt-esm-hook.conf

# Update command-not-found database
RUN apt-get update

0 comments on commit c74c57c

Please sign in to comment.