Skip to content

Commit

Permalink
Move ci from private cloud to docker (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinkle23897 authored Dec 28, 2022
1 parent 494a409 commit 1f1c12f
Show file tree
Hide file tree
Showing 19 changed files with 193 additions and 171 deletions.
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
build --action_env=BAZEL_LINKLIBS=-l%:libstdc++.a:-lm
build --action_env=BAZEL_LINKOPTS=-static-libgcc
build --action_env=CUDA_DIR=/usr/local/cuda
build --action_env=LD_LIBRARY_PATH=/home/ubuntu/.mujoco/mujoco210/bin:/usr/lib/nvidia
build --action_env=LD_LIBRARY_PATH=/usr/local/lib:/usr/lib/nvidia
build --incompatible_strict_action_env --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 --client_env=BAZEL_CXXOPTS=-std=c++17
build:debug --cxxopt=-DENVPOOL_TEST --compilation_mode=dbg -s
build:test --cxxopt=-DENVPOOL_TEST --copt=-g0 --copt=-O3 --copt=-DNDEBUG --copt=-msse --copt=-msse2 --copt=-mmmx
Expand Down
11 changes: 11 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ Checks: '
-readability-magic-numbers,
-readability-static-accessed-through-instance,
-readability-uppercase-literal-suffix,
-bugprone-easily-swappable-parameters,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-narrowing-conversions,
-google-readability-casting,
-modernize-return-braced-init-list,
-modernize-use-default-member-init,
-performance-no-int-to-ptr,
-readability-function-cognitive-complexity,
-readability-identifier-length,
-readability-redundant-smartptr-get,
-readability-simplify-boolean-expr,
'
CheckOptions:
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Cancel previous run
uses: styfle/cancel-workflow-action@0.9.1
uses: styfle/cancel-workflow-action@0.11.0
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '^1.17.3'
- name: Set up Python 3.8
uses: actions/setup-python@v2
go-version: '>=1.16.0'
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: '3.10'
- name: Upgrade pip
run: |
python -m pip install --upgrade pip
Expand Down
22 changes: 8 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,25 @@ on:

jobs:
release:
runs-on: ${{ matrix.python-version }}
runs-on: ubuntu-latest
container: trinkle23897/envpool-release:2022-12-28-e857ca2
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
steps:
- name: Cancel previous run
uses: styfle/cancel-workflow-action@0.9.1
uses: styfle/cancel-workflow-action@0.11.0
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '^1.17.3'
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
run: |
ln -sf /root/.cache $HOME/.cache
ln -sf /root/.pyenv $HOME/.pyenv
pyenv global ${{ matrix.python-version }}-dev
# uses: actions/setup-python@v2
# with:
# python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
- name: Build
run: |
make pypi-wheel BAZELOPT="--remote_cache=http://bazel-cache.sail:8080"
make pypi-wheel
pip3 install wheelhouse/*.whl --force-reinstall
- name: Test
run: |
Expand Down
18 changes: 4 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,13 @@ jobs:
runs-on: [self-hosted, Linux, X64, Test]
steps:
- name: Cancel previous run
uses: styfle/cancel-workflow-action@0.9.1
uses: styfle/cancel-workflow-action@0.11.0
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '^1.17.3'
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
- uses: actions/checkout@v3
- name: Test
run: |
make bazel-test BAZELOPT="--remote_cache=http://bazel-cache.sail:8080"
make bazel-test
- name: Run clang-tidy
run: |
make clang-tidy BAZELOPT="--remote_cache=http://bazel-cache.sail:8080"
make clang-tidy
66 changes: 43 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ BAZEL_FILES = $(shell find . -type f -name "*BUILD" -o -name "*.bzl")
COMMIT_HASH = $(shell git log -1 --format=%h)
COPYRIGHT = "Garena Online Private Limited"
BAZELOPT =
DATE = $(shell date "+%Y-%m-%d")
DOCKER_TAG = $(DATE)-$(COMMIT_HASH)
DOCKER_USER = trinkle23897
PATH := $(HOME)/go/bin:$(PATH)

# installation
Expand Down Expand Up @@ -36,7 +39,7 @@ clang-tidy-install:

go-install:
# requires go >= 1.16
command -v go || (sudo apt-get install -y golang-1.16 && sudo ln -sf /usr/lib/go-1.16/bin/go /usr/bin/go)
command -v go || (sudo apt-get install -y golang-1.18 && sudo ln -sf /usr/lib/go-1.18/bin/go /usr/bin/go)

bazel-install: go-install
command -v bazel || (go install github.com/bazelbuild/bazelisk@latest && ln -sf $(HOME)/go/bin/bazelisk $(HOME)/go/bin/bazel)
Expand All @@ -55,7 +58,7 @@ doc-install:
$(call check_install_extra, sphinxcontrib.spelling, sphinxcontrib.spelling pyenchant)

auditwheel-install:
$(call check_install_extra, auditwheel, auditwheel typed-ast)
$(call check_install_extra, auditwheel, auditwheel typed-ast patchelf)

# python linter

Expand Down Expand Up @@ -83,28 +86,31 @@ buildifier: buildifier-install

# bazel build/test

clang-tidy: clang-tidy-install
bazel-pip-requirement-dev:
cp third_party/pip_requirements/requirements-dev.txt third_party/pip_requirements/requirements.txt

bazel-pip-requirement-release:
cp third_party/pip_requirements/requirements-release.txt third_party/pip_requirements/requirements.txt

clang-tidy: clang-tidy-install bazel-pip-requirement-dev
bazel build $(BAZELOPT) //... --config=clang-tidy --config=test

bazel-debug: bazel-install
bazel build $(BAZELOPT) //... --config=debug
bazel-debug: bazel-install bazel-pip-requirement-dev
bazel run $(BAZELOPT) //:setup --config=debug -- bdist_wheel
mkdir -p dist
cp bazel-bin/setup.runfiles/$(PROJECT_NAME)/dist/*.whl ./dist

bazel-build: bazel-install
bazel build $(BAZELOPT) //... --config=test
bazel-build: bazel-install bazel-pip-requirement-dev
bazel run $(BAZELOPT) //:setup --config=test -- bdist_wheel
mkdir -p dist
cp bazel-bin/setup.runfiles/$(PROJECT_NAME)/dist/*.whl ./dist

bazel-release: bazel-install
bazel build $(BAZELOPT) //... --config=release
bazel-release: bazel-install bazel-pip-requirement-release
bazel run $(BAZELOPT) //:setup --config=release -- bdist_wheel
mkdir -p dist
cp bazel-bin/setup.runfiles/$(PROJECT_NAME)/dist/*.whl ./dist

bazel-test: bazel-install
bazel-test: bazel-install bazel-pip-requirement-dev
bazel test --test_output=all $(BAZELOPT) //... --config=test --spawn_strategy=local --color=yes

bazel-clean: bazel-install
Expand All @@ -113,7 +119,7 @@ bazel-clean: bazel-install
# documentation

addlicense: addlicense-install
addlicense -c $(COPYRIGHT) -l apache -y 2022 -check $(PROJECT_FOLDER)
addlicense -c $(COPYRIGHT) -l apache -y 2023 -check $(PROJECT_FOLDER)

docstyle: doc-install
pydocstyle $(PROJECT_NAME) && doc8 docs && cd docs && make html SPHINXOPTS="-W"
Expand All @@ -138,26 +144,40 @@ format: py-format-install clang-format-install buildifier-install addlicense-ins
yapf -ir $(PYTHON_FILES)
clang-format-11 -style=file -i $(CPP_FILES)
buildifier -r -lint=fix $(BAZEL_FILES)
addlicense -c $(COPYRIGHT) -l apache -y 2022 $(PROJECT_FOLDER)
addlicense -c $(COPYRIGHT) -l apache -y 2023 $(PROJECT_FOLDER)

# Build docker images

docker-dev:
docker build --network=host -t $(PROJECT_NAME):$(COMMIT_HASH) -f docker/dev.dockerfile .
docker run --network=host -v /:/host -it $(PROJECT_NAME):$(COMMIT_HASH) bash
echo successfully build docker image with tag $(PROJECT_NAME):$(COMMIT_HASH)
docker-ci:
docker build --network=host -t $(PROJECT_NAME):$(DOCKER_TAG) -f docker/dev.dockerfile .
echo successfully build docker image with tag $(PROJECT_NAME):$(DOCKER_TAG)

docker-ci-push: docker-ci
docker tag $(PROJECT_NAME):$(DOCKER_TAG) $(DOCKER_USER)/$(PROJECT_NAME):$(DOCKER_TAG)
docker push $(DOCKER_USER)/$(PROJECT_NAME):$(DOCKER_TAG)

docker-ci-launch: docker-ci
docker run --network=host -v /home/ubuntu:/home/github-action -it $(PROJECT_NAME):$(DOCKER_TAG) bash

docker-dev: docker-ci
docker run --network=host -v /:/host -it $(PROJECT_NAME):$(DOCKER_TAG) bash

# for mainland China
docker-dev-cn:
docker build --network=host -t $(PROJECT_NAME):$(COMMIT_HASH) -f docker/dev-cn.dockerfile .
docker run --network=host -v /:/host -it $(PROJECT_NAME):$(COMMIT_HASH) bash
echo successfully build docker image with tag $(PROJECT_NAME):$(COMMIT_HASH)
docker build --network=host -t $(PROJECT_NAME):$(DOCKER_TAG) -f docker/dev-cn.dockerfile .
echo successfully build docker image with tag $(PROJECT_NAME):$(DOCKER_TAG)
docker run --network=host -v /:/host -it $(PROJECT_NAME):$(DOCKER_TAG) bash

docker-release:
docker build --network=host -t $(PROJECT_NAME)-release:$(COMMIT_HASH) -f docker/release.dockerfile .
mkdir -p wheelhouse
docker run --network=host -v `pwd`/wheelhouse:/whl -it $(PROJECT_NAME)-release:$(COMMIT_HASH) bash -c "cp wheelhouse/* /whl"
echo successfully build docker image with tag $(PROJECT_NAME)-release:$(COMMIT_HASH)
docker build --network=host -t $(PROJECT_NAME)-release:$(DOCKER_TAG) -f docker/release.dockerfile .
echo successfully build docker image with tag $(PROJECT_NAME)-release:$(DOCKER_TAG)

docker-release-push: docker-release
docker tag $(PROJECT_NAME)-release:$(DOCKER_TAG) $(DOCKER_USER)/$(PROJECT_NAME)-release:$(DOCKER_TAG)
docker push $(DOCKER_USER)/$(PROJECT_NAME)-release:$(DOCKER_TAG)

docker-release-launch: docker-release
docker run --network=host -v /:/host -it $(PROJECT_NAME)-release:$(DOCKER_TAG) bash

pypi-wheel: auditwheel-install bazel-release
ls dist/*.whl -Art | tail -n 1 | xargs auditwheel repair --plat manylinux_2_17_x86_64
Expand Down
18 changes: 11 additions & 7 deletions docker/dev-cn.dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
FROM ubuntu:20.04
# Need docker >= 20.10.9, see https://stackoverflow.com/questions/71941032/why-i-cannot-run-apt-update-inside-a-fresh-ubuntu22-04

FROM nvidia/cuda:11.7.1-cudnn8-devel-ubuntu22.04

ARG DEBIAN_FRONTEND=noninteractive
ARG HOME=/root
ARG PATH=$PATH:$HOME/go/bin

RUN apt-get update \
&& apt-get install -y python3-pip python3-dev golang-1.16 clang-format-11 git wget swig \
&& apt-get install -y python3-pip python3-dev golang-1.18 clang-format-11 git wget swig tmux clang-tidy \
&& rm -rf /var/lib/apt/lists/*
RUN ln -s /usr/bin/python3 /usr/bin/python
RUN ln -sf /usr/lib/go-1.16/bin/go /usr/bin/go
RUN ln -sf /usr/lib/go-1.18/bin/go /usr/bin/go
RUN go env -w GOPROXY=https://goproxy.cn

RUN wget https://mirrors.huaweicloud.com/bazel/5.1.1/bazel-5.1.1-linux-x86_64
RUN chmod +x bazel-5.1.1-linux-x86_64
RUN wget https://mirrors.huaweicloud.com/bazel/6.0.0/bazel-6.0.0-linux-x86_64
RUN chmod +x bazel-6.0.0-linux-x86_64
RUN mkdir -p $HOME/go/bin
RUN mv bazel-5.1.1-linux-x86_64 $HOME/go/bin/bazel
RUN mv bazel-6.0.0-linux-x86_64 $HOME/go/bin/bazel
RUN go install github.com/bazelbuild/buildtools/buildifier@latest
RUN pip3 install --upgrade pip isort yapf cpplint flake8 flake8_bugbear mypy && rm -rf ~/.pip/cache
RUN $HOME/go/bin/bazel version

RUN useradd -ms /bin/bash github-action

WORKDIR /app
COPY . .
12 changes: 8 additions & 4 deletions docker/dev.dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
FROM ubuntu:20.04
# Need docker >= 20.10.9, see https://stackoverflow.com/questions/71941032/why-i-cannot-run-apt-update-inside-a-fresh-ubuntu22-04

FROM nvidia/cuda:11.7.1-cudnn8-devel-ubuntu22.04

ARG DEBIAN_FRONTEND=noninteractive
ARG HOME=/root
ARG PATH=$PATH:$HOME/go/bin

RUN apt-get update \
&& apt-get install -y python3-pip python3-dev golang-1.16 clang-format-11 git wget swig \
&& apt-get install -y python3-pip python3-dev golang-1.18 clang-format-11 git wget swig tmux clang-tidy \
&& rm -rf /var/lib/apt/lists/*
RUN ln -s /usr/bin/python3 /usr/bin/python
RUN ln -sf /usr/lib/go-1.16/bin/go /usr/bin/go
RUN ln -sf /usr/lib/go-1.18/bin/go /usr/bin/go

RUN go install github.com/bazelbuild/bazelisk@latest && ln -sf $HOME/go/bin/bazelisk $HOME/go/bin/bazel
RUN go install github.com/bazelbuild/buildtools/buildifier@latest
RUN pip3 install --upgrade pip isort yapf cpplint flake8 flake8_bugbear mypy && rm -rf ~/.pip/cache
RUN $HOME/go/bin/bazel version

RUN useradd -ms /bin/bash github-action

WORKDIR /app
COPY . .
60 changes: 38 additions & 22 deletions docker/release.dockerfile
Original file line number Diff line number Diff line change
@@ -1,48 +1,64 @@
FROM ubuntu:16.04
FROM nvidia/cuda:11.3.1-cudnn8-devel-ubuntu16.04

ARG DEBIAN_FRONTEND=noninteractive
ARG HOME=/root
ENV PATH=$HOME/go/bin:$PATH
ENV PATH=$HOME/go/bin:$HOME/.pyenv/shims:$HOME/.pyenv/bin:$PATH
ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

WORKDIR $HOME

# install base dependencies

RUN apt-get update && apt-get install -y software-properties-common && add-apt-repository ppa:ubuntu-toolchain-r/test && add-apt-repository ppa:deadsnakes/ppa
RUN apt-get update && apt-get install -y software-properties-common && add-apt-repository ppa:ubuntu-toolchain-r/test

RUN apt-get update \
&& apt-get install -y git curl wget gcc-9 g++-9 build-essential patchelf make libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev swig \
python3.7 python3.8 python3.9 python3.10 \
python3.7-dev python3.8-dev python3.9-dev python3.10-dev \
python3.8-distutils python3.9-distutils python3.10-distutils
RUN ln -sf /usr/bin/python3 /usr/bin/python
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-9
&& apt-get install -y git curl wget gcc-9 g++-9 build-essential swig make \
zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev libncursesw5-dev libffi-dev liblzma-dev \
llvm xz-utils tk-dev libxml2-dev libxmlsec1-dev
# use self-compiled openssl instead of system provided (1.0.2)
RUN apt-get remove -y libssl-dev

# install pip
RUN curl https://pyenv.run | sh

RUN wget https://bootstrap.pypa.io/get-pip.py
RUN for i in 7 8 9 10; do ln -sf /usr/bin/python3.$i /usr/bin/python3; python3 get-pip.py; done
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-9

# install go from source

RUN wget https://golang.org/dl/go1.17.3.linux-amd64.tar.gz
RUN rm -rf /usr/local/go && tar -C /usr/local -xzf go1.17.3.linux-amd64.tar.gz
RUN wget https://golang.org/dl/go1.19.4.linux-amd64.tar.gz
RUN rm -rf /usr/local/go && tar -C /usr/local -xzf go1.19.4.linux-amd64.tar.gz
RUN ln -sf /usr/local/go/bin/go /usr/bin/go

# install bazel

RUN go install github.com/bazelbuild/bazelisk@latest && ln -sf $HOME/go/bin/bazelisk $HOME/go/bin/bazel

# install big wheels
RUN bazel version

# install newest openssl (for py3.10 and py3.11)

RUN for i in 7 8 9 10; do ln -sf /usr/bin/python3.$i /usr/bin/python3; pip3 install torch opencv-python-headless; done
RUN wget https://www.openssl.org/source/openssl-1.1.1s.tar.gz
RUN tar xf openssl-1.1.1s.tar.gz
WORKDIR $HOME/openssl-1.1.1s
RUN ./config
RUN make -j
RUN make install

RUN bazel version
# install python

RUN echo 'export PYENV_ROOT="$HOME/.pyenv"' >> /etc/profile
RUN echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> /etc/profile
RUN echo 'eval "$(pyenv init -)"' >> /etc/profile

RUN LDFLAGS="-Wl,-rpath,/root/openssl-1.1.1s/lib" CONFIGURE_OPTS="-with-openssl=/root/openssl-1.1.1s" pyenv install -v 3.11-dev
RUN LDFLAGS="-Wl,-rpath,/root/openssl-1.1.1s/lib" CONFIGURE_OPTS="-with-openssl=/root/openssl-1.1.1s" pyenv install -v 3.10-dev
RUN LDFLAGS="-Wl,-rpath,/root/openssl-1.1.1s/lib" CONFIGURE_OPTS="-with-openssl=/root/openssl-1.1.1s" pyenv install -v 3.9-dev
RUN LDFLAGS="-Wl,-rpath,/root/openssl-1.1.1s/lib" CONFIGURE_OPTS="-with-openssl=/root/openssl-1.1.1s" pyenv install -v 3.8-dev
RUN LDFLAGS="-Wl,-rpath,/root/openssl-1.1.1s/lib" CONFIGURE_OPTS="-with-openssl=/root/openssl-1.1.1s" pyenv install -v 3.7-dev

WORKDIR /app
WORKDIR /__w/envpool/envpool
COPY . .

# compile and test release wheels
# cache bazel build (cpp only)

RUN for i in 7 8 9 10; do ln -sf /usr/bin/python3.$i /usr/bin/python3; make pypi-wheel BAZELOPT="--remote_cache=http://bazel-cache.sail:8080"; pip3 install wheelhouse/*cp3$i*.whl; rm dist/*.whl; make release-test; done
RUN bazel build //envpool/utils:image_process_test --config=release
RUN bazel build //envpool/vizdoom/bin:vizdoom_bin --config=release
Loading

0 comments on commit 1f1c12f

Please sign in to comment.