Skip to content

Commit f074f77

Browse files
authored
Add Ubuntu Docker images (#1)
This change adds Docker images for Ubuntu 22.04 (jammy) and 24.04 (noble), with GCC or Clang if supported.
1 parent 6ecd920 commit f074f77

File tree

5 files changed

+228
-1
lines changed

5 files changed

+228
-1
lines changed

.github/workflows/ubuntu.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Ubuntu
2+
3+
on: push
4+
5+
env:
6+
DOCKER_REGISTRY: ghcr.io
7+
8+
jobs:
9+
# Build the Docker image for Ubuntu using different versions of GCC.
10+
gcc:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
version:
15+
- os: jammy
16+
gcc: 12
17+
- os: noble
18+
gcc: 13
19+
- os: noble
20+
gcc: 14
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
- name: Login to GitHub Container Registry
25+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ${DOCKER_REGISTRY} -u ${{ github.repository_owner }} --password-stdin
26+
- name: Determine the Docker image name.
27+
run: |
28+
# Convert the repository name to lowercase as the organization name is
29+
# uppercase, which is not permitted by the Docker registry.
30+
DOCKER_REPOSITORY=${GITHUB_REPOSITORY,,}
31+
echo "DOCKER_IMAGE=${DOCKER_REGISTRY}/${DOCKER_REPOSITORY}/${{ matrix.version.os }}:gcc${{ matrix.version.gcc }}" >> $GITHUB_ENV
32+
- name: Build the Docker image
33+
working-directory: docker/ubuntu
34+
run: |
35+
DOCKER_BUILDKIT=1 docker build . \
36+
--target gcc \
37+
--build-arg GITHUB_REPO=${GITHUB_REPOSITORY} \
38+
--build-arg UBUNTU_VERSION=${{ matrix.version.os }} \
39+
--build-arg GCC_VERSION=${{ matrix.version.gcc }} \
40+
--tag ${{ env.DOCKER_IMAGE }}
41+
- name: Push the Docker image
42+
run: docker push ${{ env.DOCKER_IMAGE }}
43+
44+
# Build the Docker image for Ubuntu using different versions of Clang.
45+
clang:
46+
runs-on: ubuntu-latest
47+
strategy:
48+
matrix:
49+
version:
50+
- os: noble
51+
clang: 16
52+
- os: noble
53+
clang: 17
54+
- os: noble
55+
clang: 18
56+
- os: noble
57+
clang: 19
58+
steps:
59+
- name: Checkout repository
60+
uses: actions/checkout@v4
61+
- name: Login to GitHub Container Registry
62+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ${DOCKER_REGISTRY} -u ${{ github.repository_owner }} --password-stdin
63+
- name: Determine the Docker image name.
64+
run: |
65+
# Convert the repository name to lowercase as the organization name is
66+
# uppercase, which is not permitted by the Docker registry.
67+
DOCKER_REPOSITORY=${GITHUB_REPOSITORY,,}
68+
echo "DOCKER_IMAGE=${DOCKER_REGISTRY}/${DOCKER_REPOSITORY}/${{ matrix.version.os }}:clang${{ matrix.version.clang }}" >> $GITHUB_ENV
69+
- name: Build the Docker image
70+
working-directory: docker/ubuntu
71+
run: |
72+
DOCKER_BUILDKIT=1 docker build . \
73+
--target clang \
74+
--build-arg GITHUB_REPO=${GITHUB_REPOSITORY} \
75+
--build-arg UBUNTU_VERSION=${{ matrix.version.os }} \
76+
--build-arg CLANG_VERSION=${{ matrix.version.clang }} \
77+
--tag ${{ env.DOCKER_IMAGE }}
78+
- name: Push the Docker image
79+
run: docker push ${{ env.DOCKER_IMAGE }}

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# IDEs.
2+
.idea
3+
.vscode
4+
settings.json
5+
6+
# OS.
7+
.DS_Store

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
# ci
1+
# CI
2+
23
Images and workflows for use by CI pipelines.

docker/ubuntu/Dockerfile

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# ====================== BASE IMAGE ======================
2+
ARG UBUNTU_VERSION=jammy
3+
FROM ubuntu:${UBUNTU_VERSION} AS base
4+
5+
# Associate the image with the repository.
6+
ARG GITHUB_REPO=XRPLF/ci
7+
LABEL org.opencontainers.image.source=https://github.com/${GITHUB_REPO}
8+
9+
# Ensure any packages installed directly or indirectly via dpkg do not require
10+
# manual interaction.
11+
ARG DEBIAN_FRONTEND=noninteractive
12+
RUN apt update && apt upgrade -y && \
13+
ln -fs /usr/share/zoneinfo/America/Los_Angeles /etc/localtime && \
14+
apt install tzdata && \
15+
dpkg-reconfigure --frontend noninteractive tzdata
16+
17+
# Install tools that are shared by all stages.
18+
RUN apt install -y build-essential \
19+
ca-certificates \
20+
cmake \
21+
curl \
22+
git \
23+
gpg \
24+
libssl-dev \
25+
libprotobuf-dev \
26+
ninja-build \
27+
protobuf-compiler
28+
29+
# Install Conan.
30+
RUN apt install -y pipx
31+
RUN PIPX_HOME=/opt/pipx \
32+
PIPX_BIN_DIR=/usr/bin \
33+
PIPX_MAN_DIR=/usr/share/man \
34+
pipx install conan
35+
36+
# Create the user to switch to, once all packages have been installed.
37+
ARG NONROOT_USER=ci
38+
RUN useradd -ms /bin/bash ${NONROOT_USER}
39+
40+
# ====================== GCC IMAGE ======================
41+
FROM base AS gcc
42+
43+
# Install GCC.
44+
ARG GCC_VERSION=12
45+
RUN apt install -y gcc-${GCC_VERSION} g++-${GCC_VERSION}
46+
ENV CC=/usr/bin/gcc-${GCC_VERSION}
47+
ENV CXX=/usr/bin/gcc-${GCC_VERSION}
48+
RUN rm -rf /var/lib/apt/lists/*
49+
50+
# Switch to the non-root user.
51+
USER ${NONROOT_USER}
52+
WORKDIR /home/${NONROOT_USER}
53+
54+
# ===================== CLANG IMAGE =====================
55+
FROM base AS clang
56+
57+
# Install Clang.
58+
ARG CLANG_VERSION=16
59+
RUN apt install -y clang-${CLANG_VERSION} llvm-${CLANG_VERSION}
60+
ENV CC=/usr/bin/clang-${CLANG_VERSION}
61+
ENV CXX=/usr/bin/clang++-${CLANG_VERSION}
62+
RUN rm -rf /var/lib/apt/lists/*
63+
64+
# Switch to the non-root user.
65+
USER ${NONROOT_USER}
66+
WORKDIR /home/${NONROOT_USER}

docker/ubuntu/README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
## Ubuntu: A Docker image used to build and test rippled
2+
3+
The code in this repository creates a locked-down Ubuntu image for building and
4+
testing rippled in the GitHub CI pipelines.
5+
6+
Although the images will be built by a CI pipeline in this repository, if
7+
necessary a maintainer can build them manually by following the instructions
8+
below.
9+
10+
### Logging into the Docker registry
11+
12+
To be able to push to GitHub a personal access token is needed, see instructions
13+
[here](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#authenticating-with-a-personal-access-token-classic).
14+
In summary, if you do not have a suitable personal access token, generate one
15+
[here](https://github.com/settings/tokens/new?scopes=write:packages).
16+
17+
```shell
18+
DOCKER_REGISTRY=ghcr.io
19+
GITHUB_USER=<your-github-username>
20+
GITHUB_TOKEN=<your-github-personal-access-token>
21+
echo ${GITHUB_TOKEN} | \
22+
docker login ${DOCKER_REGISTRY} -u "${GITHUB_USER}" --password-stdin
23+
```
24+
25+
### Building and pushing the Docker image
26+
27+
The same Dockerfile can be used to build an image for Ubuntu 22.04 and 24.04 by
28+
specifying the `UBUNTU_VERSION` build argument. There are additional arguments
29+
to specify as well, namely `CMAKE_VERSION` and `GCC_VERSION` for the GCC flavor
30+
and `CMAKE_VERSION` and `CLANG_VERSION` for the Clang flavor.
31+
32+
Run the commands below from the current directory containing the Dockerfile.
33+
34+
#### Building the Docker image for GCC.
35+
36+
Ensure you've run the login command above to authenticate with the Docker
37+
registry.
38+
39+
```shell
40+
UBUNTU_VERSION=noble
41+
GCC_VERSION=14
42+
DOCKER_IMAGE=xrplf/ci/${UBUNTU_VERSION}:gcc${GCC_VERSION}
43+
44+
DOCKER_BUILDKIT=1 docker build . \
45+
--target gcc \
46+
--build-arg BUILDKIT_INLINE_CACHE=1 \
47+
--build-arg UBUNTU_VERSION=${UBUNTU_VERSION} \
48+
--build-arg GCC_VERSION=${GCC_VERSION} \
49+
--tag ${DOCKER_REGISTRY}/${DOCKER_IMAGE} \
50+
--platform linux/amd64
51+
52+
docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}
53+
```
54+
55+
#### Building the Docker image for Clang.
56+
57+
Ensure you've run the login command above to authenticate with the Docker
58+
registry.
59+
60+
```shell
61+
UBUNTU_VERSION=noble
62+
CLANG_VERSION=18
63+
DOCKER_IMAGE=xrplf/ci/${UBUNTU_VERSION}:clang${CLANG_VERSION}
64+
65+
DOCKER_BUILDKIT=1 docker build . \
66+
--target clang \
67+
--build-arg BUILDKIT_INLINE_CACHE=1 \
68+
--build-arg UBUNTU_VERSION=${UBUNTU_VERSION} \
69+
--build-arg CLANG_VERSION=${CLANG_VERSION} \
70+
--tag ${DOCKER_REGISTRY}/${DOCKER_IMAGE} \
71+
--platform linux/amd64
72+
73+
docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}
74+
```

0 commit comments

Comments
 (0)