Skip to content
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

Refactor into a base image. #953

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
144 changes: 139 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
- name: Run unit tests
run: cargo test --locked --all-targets --workspace --all-features
timeout-minutes: 10

check:
runs-on: ubuntu-latest
outputs:
Expand All @@ -84,6 +85,7 @@ jobs:
- uses: ./.github/actions/setup-rust
- run: cargo xtask ci-job check
id: check

generate-matrix:
runs-on: ubuntu-latest
outputs:
Expand All @@ -99,10 +101,109 @@ jobs:
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
COMMIT_AUTHOR: ${{ github.event.head_commit.author.username }}

build-base:
Alexhuszagh marked this conversation as resolved.
Show resolved Hide resolved
name: ${{ matrix.image }} (${{ matrix.sub }})
runs-on: ubuntu-latest
needs: [shellcheck, test, check]
if: github.event_name == 'push'
strategy:
fail-fast: false
matrix:
image:
- base
sub:
- ubuntu
- centos
- emscripten
outputs:
coverage-artifact: ${{ steps.cov.outputs.artifact-name }}
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-rust

- name: Set up Docker Buildx
if: runner.os == 'Linux'
uses: docker/setup-buildx-action@v1

- name: Build xtask
run: cargo build -p xtask

- name: Prepare Meta
id: prepare-meta
timeout-minutes: 60
run: cargo xtask ci-job prepare-meta "${IMAGE}.${SUB}"
env:
IMAGE: ${{ matrix.image }}
SUB: ${{ matrix.sub }}
shell: bash

- name: LLVM instrument coverage
uses: ./.github/actions/cargo-llvm-cov
with:
name: cross-${{matrix.image}}-${{matrix.sub}}

- name: Install cross
if: matrix.deploy
run: cargo install --path . --force --debug

- name: Docker Meta
id: docker-meta
uses: docker/metadata-action@v4
with:
images: |
name=${{ steps.prepare-meta.outputs.image }}
labels: |
${{ fromJSON(steps.prepare-meta.outputs.labels) }}

# always use the main branch, since we need it for the base image
- name: Build Docker image
id: build-docker-image
timeout-minutes: 60
run: cargo xtask build-docker-image -v --tag main "${IMAGE}.${SUB}"
env:
IMAGE: ${{ matrix.image }}
SUB: ${{ matrix.sub }}
LABELS: ${{ steps.docker-meta.outputs.labels }}
LATEST: ${{ needs.check.outputs.is-latest || 'false' }}
shell: bash

- name: Save Docker Image
id: save-docker-image
run: docker save "ghcr.io/cross-rs/${IMAGE}:main-${SUB}" -o "${IMAGE}-main-${SUB}.tar"
env:
IMAGE: ${{ matrix.image }}
SUB: ${{ matrix.sub }}

- uses: actions/upload-artifact@v2
with:
name: ${{ matrix.image }}-${{ matrix.sub }}-image-tarball
path: ${{ matrix.image }}-main-${{ matrix.sub }}.tar

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push image to GitHub Container Registry
if: >
(
github.ref == format('refs/heads/{0}', github.event.repository.default_branch) ||
startsWith(github.ref, 'refs/tags/v')
)
run: cargo xtask build-docker-image -v "${IMAGE}.${SUB}"
env:
IMAGE: ${{ matrix.image }}
SUB: ${{ matrix.sub }}
LABELS: ${{ steps.docker-meta.outputs.labels }}
LATEST: ${{ needs.check.outputs.is-latest || 'false' }}
shell: bash

build:
name: target (${{ matrix.pretty }},${{ matrix.os }})
runs-on: ${{ matrix.os }}
needs: [shellcheck, test, generate-matrix, check]
needs: [shellcheck, test, generate-matrix, check, build-base]
if: github.event_name == 'push' && needs.generate-matrix.outputs.matrix != '{}' && needs.generate-matrix.outputs.matrix != '[]' && needs.generate-matrix.outputs.matrix != ''
strategy:
fail-fast: false
Expand All @@ -114,7 +215,6 @@ jobs:
coverage-artifact: ${{ steps.cov.outputs.artifact-name }}
steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/setup-rust

- name: Set up Docker Buildx
Expand Down Expand Up @@ -153,6 +253,33 @@ jobs:
name=${{ steps.prepare-meta.outputs.image }}
labels: |
${{ fromJSON(steps.prepare-meta.outputs.labels) }}

- name: Set env Base Image
if: steps.prepare-meta.outputs.has-image
run: |
if [[ "${SUB}" == "centos" ]]; then
echo "BASE=centos" >> "${GITHUB_ENV}"
elif [[ "${TARGET}" == *emscripten ]]; then
echo "BASE=emscripten" >> "${GITHUB_ENV}"
else
echo "BASE=ubuntu" >> "${GITHUB_ENV}"
fi
env:
TARGET: ${{ matrix.target }}
SUB: ${{ matrix.sub }}

- uses: actions/download-artifact@v3
if: steps.prepare-meta.outputs.has-image
with:
name: base-${{ env.BASE }}-image-tarball

- name: Load Base Image
id: load-docker-image
if: steps.prepare-meta.outputs.has-image
run: docker load --input "base-main-${BASE}.tar"
env:
SUB: ${{ matrix.sub }}

- name: Build Docker image
id: build-docker-image
if: steps.prepare-meta.outputs.has-image
Expand All @@ -163,7 +290,9 @@ jobs:
SUB: ${{ matrix.sub }}
LABELS: ${{ steps.docker-meta.outputs.labels }}
LATEST: ${{ needs.check.outputs.is-latest || 'false' }}
CROSS_CONTAINER_ENGINE_NO_PULL: true
shell: bash

- name: Set Docker image for test
if: steps.prepare-meta.outputs.has-image
run: |
Expand All @@ -173,6 +302,7 @@ jobs:
TARGET: ${{ matrix.target }}
IMAGE: ${{ steps.build-docker-image.outputs.image }}
shell: bash

- name: Test Image
if: steps.prepare-meta.outputs.has-image && steps.prepare-meta.outputs.test-variant == 'default'
run: ./ci/test.sh
Expand All @@ -185,6 +315,7 @@ jobs:
RUN: ${{ matrix.run }}
RUNNERS: ${{ matrix.runners }}
shell: bash

- uses: ./.github/actions/cargo-install-upload-artifacts
if: matrix.deploy
with:
Expand All @@ -210,6 +341,7 @@ jobs:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push image to GitHub Container Registry
if: >
steps.prepare-meta.outputs.has-image && (
Expand Down Expand Up @@ -275,15 +407,18 @@ jobs:
uses: ./.github/actions/cargo-llvm-cov
with:
name: integration-bisect

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: arm64

- name: Set up docker buildx
uses: docker/setup-buildx-action@v2
id: buildx
with:
install: true

- name: Run Foreign toolchain test
run: ./ci/test-foreign-toolchain.sh
shell: bash
Expand Down Expand Up @@ -321,7 +456,6 @@ jobs:
coverage-artifact: ${{ steps.cov.outputs.artifact-name }}
steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/setup-rust

- name: Install Podman
Expand All @@ -348,7 +482,7 @@ jobs:
shell: bash

publish:
needs: [build, check, fmt, clippy, cargo-deny]
needs: [build-base, build, check, fmt, clippy, cargo-deny]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -359,7 +493,7 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}

conclusion:
needs: [shellcheck, fmt, clippy, test, generate-matrix, build, publish, check, remote, bisect, docker-in-docker, foreign, podman]
needs: [shellcheck, fmt, clippy, test, generate-matrix, build-base, build, publish, check, remote, bisect, docker-in-docker, foreign, podman]
if: always()
runs-on: ubuntu-latest
steps:
Expand Down
11 changes: 1 addition & 10 deletions docker/Dockerfile.aarch64-linux-android
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
FROM ubuntu:20.04
FROM ghcr.io/cross-rs/base:main-ubuntu
ARG DEBIAN_FRONTEND=noninteractive

COPY common.sh lib.sh /
RUN /common.sh

COPY cmake.sh /
RUN /cmake.sh

COPY xargo.sh /
RUN /xargo.sh

COPY android-ndk.sh /
RUN /android-ndk.sh arm64 28
ENV PATH=$PATH:/android-ndk/bin
Expand Down
11 changes: 1 addition & 10 deletions docker/Dockerfile.aarch64-unknown-linux-gnu
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
FROM ubuntu:20.04
FROM ghcr.io/cross-rs/base:main-ubuntu
ARG DEBIAN_FRONTEND=noninteractive

COPY common.sh lib.sh /
RUN /common.sh

COPY cmake.sh /
RUN /cmake.sh

COPY xargo.sh /
RUN /xargo.sh

RUN apt-get update && apt-get install --assume-yes --no-install-recommends \
g++-aarch64-linux-gnu \
libc6-dev-arm64-cross
Expand Down
11 changes: 1 addition & 10 deletions docker/Dockerfile.aarch64-unknown-linux-gnu.centos
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@ COPY lib.sh /
COPY linux-image.sh /
RUN /linux-image.sh aarch64

FROM centos:7

COPY common.sh lib.sh /
RUN /common.sh

COPY cmake.sh /
RUN /cmake.sh

COPY xargo.sh /
RUN /xargo.sh
FROM ghcr.io/cross-rs/base:main-centos

COPY qemu.sh /
RUN /qemu.sh aarch64 softmmu
Expand Down
11 changes: 1 addition & 10 deletions docker/Dockerfile.aarch64-unknown-linux-musl
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
FROM ubuntu:20.04
FROM ghcr.io/cross-rs/base:main-ubuntu
ARG DEBIAN_FRONTEND=noninteractive

COPY common.sh lib.sh /
RUN /common.sh

COPY cmake.sh /
RUN /cmake.sh

COPY xargo.sh /
RUN /xargo.sh

COPY qemu.sh /
RUN /qemu.sh aarch64

Expand Down
11 changes: 1 addition & 10 deletions docker/Dockerfile.arm-linux-androideabi
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
FROM ubuntu:20.04
FROM ghcr.io/cross-rs/base:main-ubuntu
ARG DEBIAN_FRONTEND=noninteractive

COPY common.sh lib.sh /
RUN /common.sh

COPY cmake.sh /
RUN /cmake.sh

COPY xargo.sh /
RUN /xargo.sh

COPY android-ndk.sh /
RUN /android-ndk.sh arm 28
ENV PATH=$PATH:/android-ndk/bin
Expand Down
11 changes: 1 addition & 10 deletions docker/Dockerfile.arm-unknown-linux-gnueabi
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
FROM ubuntu:20.04
FROM ghcr.io/cross-rs/base:main-ubuntu
ARG DEBIAN_FRONTEND=noninteractive

COPY common.sh lib.sh /
RUN /common.sh

COPY cmake.sh /
RUN /cmake.sh

COPY xargo.sh /
RUN /xargo.sh

RUN apt-get update && apt-get install --assume-yes --no-install-recommends \
g++-arm-linux-gnueabi \
libc6-dev-armel-cross
Expand Down
11 changes: 1 addition & 10 deletions docker/Dockerfile.arm-unknown-linux-gnueabihf
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
FROM ubuntu:20.04
FROM ghcr.io/cross-rs/base:main-ubuntu
ARG DEBIAN_FRONTEND=noninteractive

COPY common.sh lib.sh /
RUN /common.sh

COPY cmake.sh /
RUN /cmake.sh

COPY xargo.sh /
RUN /xargo.sh

ARG VERBOSE
COPY crosstool-ng.sh /
COPY crosstool-config/arm-unknown-linux-gnueabihf.config /
Expand Down
11 changes: 1 addition & 10 deletions docker/Dockerfile.arm-unknown-linux-musleabi
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
FROM ubuntu:20.04
FROM ghcr.io/cross-rs/base:main-ubuntu
ARG DEBIAN_FRONTEND=noninteractive

COPY common.sh lib.sh /
RUN /common.sh

COPY cmake.sh /
RUN /cmake.sh

COPY xargo.sh /
RUN /xargo.sh

COPY qemu.sh /
RUN /qemu.sh arm

Expand Down
Loading