Skip to content

[WIP] Add base Docker image for Linux CI jobs #9

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ci/docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO
20 changes: 20 additions & 0 deletions .ci/docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -ex

IMAGE_NAME="$1"
shift

OS="ubuntu"
OS_VERSION=22.04
CLANG_VERSION=12

docker build \
--no-cache \
--progress=plain \
--build-arg "IMAGE_NAME=${IMAGE_NAME}" \
--build-arg "OS_VERSION=${OS_VERSION}" \
--build-arg "CLANG_VERSION=${CLANG_VERSION}" \
-f "${OS}"/Dockerfile \
"$@" \
.
36 changes: 36 additions & 0 deletions .ci/docker/common/install_base.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

set -ex

install_ubuntu() {
apt-get update

apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
curl \
git \
wget \
sudo \
vim \
jq \
vim \
unzip \
gdb

# Cleanup package manager
apt-get autoclean && apt-get clean
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
}

# Install base packages depending on the base OS
ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
case "$ID" in
ubuntu)
install_ubuntu
;;
*)
echo "Unable to determine OS..."
exit 1
;;
esac
41 changes: 41 additions & 0 deletions .ci/docker/common/install_clang.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

set -ex

install_ubuntu() {
apt-get update

apt-get install -y --no-install-recommends clang-"$CLANG_VERSION"
apt-get install -y --no-install-recommends llvm-"$CLANG_VERSION"

# Use update-alternatives to make this version the default
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-"$CLANG_VERSION" 50
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-"$CLANG_VERSION" 50
# Override cc/c++ to clang as well
update-alternatives --install /usr/bin/cc cc /usr/bin/clang 50
update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 50

# CLANG's packaging is a little messed up (the runtime libs aren't
# added into the linker path), so give it a little help
CLANG_LIB=("/usr/lib/llvm-$CLANG_VERSION/lib/clang/"*"/lib/linux")
echo "$CLANG_LIB" > /etc/ld.so.conf.d/clang.conf
ldconfig

# Cleanup package manager
apt-get autoclean && apt-get clean
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
}

if [ -n "$CLANG_VERSION" ]; then
# Install base packages depending on the base OS
ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
case "$ID" in
ubuntu)
install_ubuntu
;;
*)
echo "Unable to determine OS..."
exit 1
;;
esac
fi
19 changes: 19 additions & 0 deletions .ci/docker/common/install_user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -ex

# Same as ec2-user
echo "ci-user:x:1000:1000::/var/lib/ci-user:" >> /etc/passwd
echo "ci-user:x:1000:" >> /etc/group
# Needed on Focal or newer
echo "ci-user:*:19110:0:99999:7:::" >> /etc/shadow

# Create $HOME
mkdir -p /var/lib/ci-user
chown ci-user:ci-user /var/lib/ci-user

# Allow sudo
echo 'ci-user ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/ci-user

# Test that sudo works
$SUDO -u ci-user $SUDO -v
22 changes: 22 additions & 0 deletions .ci/docker/ubuntu/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ARG OS_VERSION

FROM ubuntu:${OS_VERSION}

ARG OS_VERSION

ENV DEBIAN_FRONTEND noninteractive

# Install common dependencies
COPY ./common/install_base.sh install_base.sh
RUN bash ./install_base.sh && rm install_base.sh

# Install clang
COPY ./common/install_clang.sh install_clang.sh
RUN bash ./install_clang.sh && rm install_clang.sh

# Setup user
COPY ./common/install_user.sh install_user.sh
RUN bash ./install_user.sh && rm install_user.sh

USER ci-user
CMD ["bash"]
55 changes: 55 additions & 0 deletions .github/workflows/docker-builds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: docker-builds

on:
workflow_dispatch:
pull_request:
paths:
- .ci/docker/**
- .github/workflows/docker-builds.yml
push:
branches:
- main
schedule:
- cron: 1 3 * * 3

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}
cancel-in-progress: true

env:
ALPINE_IMAGE: 308535385114.dkr.ecr.us-east-1.amazonaws.com/tool/alpine
AWS_DEFAULT_REGION: us-east-1

jobs:
docker-build:
runs-on: [self-hosted, linux.2xlarge]
timeout-minutes: 240
strategy:
fail-fast: false
matrix:
include:
- docker-image-name: executorch-ubuntu-22.04-clang12
env:
DOCKER_IMAGE_BASE: 308535385114.dkr.ecr.us-east-1.amazonaws.com/pytorch/${{ matrix.docker-image-name }}
steps:
- name: Clean workspace
shell: bash
run: |
echo "${GITHUB_WORKSPACE}"
sudo rm -rf "${GITHUB_WORKSPACE}"
mkdir "${GITHUB_WORKSPACE}"

- name: Checkout Executorch
uses: actions/checkout@v3

- name: Setup Linux
uses: pytorch/test-infra/.github/actions/setup-linux@main

# TODO: Move calculate Docker image to test-infra as a shareable GHA
- name: Build docker image
id: build-docker-image
shell: bash
env:
DOCKER_IMAGE_NAME: ${{ matrix.docker-image-name }}
run: |
.ci/docker/build.sh