Build Docker image with CI

This commit is contained in:
Zhang Junyang 2023-08-10 15:29:22 +08:00 committed by Tate, Hongliang Tian
parent 7b390d9f8a
commit e7d1437fca
5 changed files with 48 additions and 36 deletions

46
.github/workflows/docker_build.yml vendored Normal file
View File

@ -0,0 +1,46 @@
name: Docker image build
on:
push:
paths:
# The image build workflow will be triggered if changes are present
# in the following files/directories. Make sure that all files used
# in the building process are listed here.
- tools/docker/**
- regression/syscall_test/**
- Cargo.toml
- rust-toolchain.toml
branches:
- 'main'
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: actions/checkout@v3
- name: Fetch versions in the repo
id: fetch-versions
run: |
echo "jinux=$( grep -m1 -o '[0-9]\+\.[0-9]\+\.[0-9]\+' Cargo.toml | sed 's/[^0-9\.]//g' )" >> "$GITHUB_OUTPUT"
echo "rust=$( grep -m1 -o 'nightly-[0-9]\+-[0-9]\+-[0-9]\+' rust-toolchain.toml )" >> "$GITHUB_OUTPUT"
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./tools/docker/Dockerfile.ubuntu22.04
platforms: linux/amd64
push: true
tags: jinuxdev/jinux:${{ steps.fetch-versions.outputs.jinux }}
build-args: |
"JINUX_RUST_VERSION=${{ steps.fetch-versions.outputs.rust }}"

View File

@ -2,11 +2,6 @@ name: Syscall test
on:
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
push:
branches:
- main

View File

@ -1 +0,0 @@
bom/

View File

@ -15,14 +15,14 @@ RUN apt update && apt-get install -y --no-install-recommends \
python3-pip
# Install bazel, which is required by the system call test suite from Gvisor project
COPY bom/syscall_test/install_bazel.sh /tmp/
COPY regression/syscall_test/install_bazel.sh /tmp/
WORKDIR /tmp
RUN ./install_bazel.sh && rm -f /tmp/install_bazel.sh
FROM ubuntu-22.04-with-bazel as syscall_test
# Build the syscall test binaries
COPY bom/syscall_test /root/syscall_test
COPY regression/syscall_test /root/syscall_test
WORKDIR /root/syscall_test
RUN export BUILD_DIR=build && \
make ${BUILD_DIR}/syscall_test_bins

View File

@ -1,28 +0,0 @@
#!/bin/bash
set -e
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
CARGO_TOML_PATH=${SCRIPT_DIR}/../../Cargo.toml
VERSION=$( grep -m1 -o '[0-9]\+\.[0-9]\+\.[0-9]\+' ${CARGO_TOML_PATH} | sed 's/[^0-9\.]//g' )
IMAGE_NAME=jinuxdev/jinux:${VERSION}
DOCKER_FILE=${SCRIPT_DIR}/Dockerfile.ubuntu22.04
BOM_DIR=${SCRIPT_DIR}/bom
TOP_DIR=${SCRIPT_DIR}/../../
ARCH=linux/amd64
RUST_TOOLCHAIN_PATH=${SCRIPT_DIR}/../../rust-toolchain.toml
JINUX_RUST_VERSION=$( grep -m1 -o 'nightly-[0-9]\+-[0-9]\+-[0-9]\+' ${RUST_TOOLCHAIN_PATH} )
# Prpare the BOM (bill of materials) directory to copy files or dirs into the docker image.
# This is because the `docker build` can not access the parent directory of the context.
if [ ! -d ${BOM_DIR} ]; then
mkdir -p ${BOM_DIR}
cp -rf ${TOP_DIR}/regression/syscall_test ${BOM_DIR}/
fi
# Build docker
cd ${SCRIPT_DIR}
docker buildx build -f ${DOCKER_FILE} \
--build-arg JINUX_RUST_VERSION=${JINUX_RUST_VERSION} \
--platform ${ARCH} \
-t ${IMAGE_NAME} .