Skip to content

Commit 41cd26a

Browse files
dborehamDavid Boreham
andcommitted
Refactor container files (#433)
Co-authored-by: David Boreham <[email protected]>
1 parent f4d0c05 commit 41cd26a

File tree

11 files changed

+106
-23
lines changed

11 files changed

+106
-23
lines changed

.github/workflows/container.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,14 @@ jobs:
2727
uses: docker/metadata-action@v5
2828
with:
2929
images: |
30-
ghcr.io/${{ github.repository }}/libra-node
30+
ghcr.io/${{ github.repository_owner }}/libra-node
3131
tags: |
32-
# tag as branch name
32+
# tag as git sha
3333
type=sha,enable=true,priority=100,prefix=,suffix=,format=long
3434
# tag canary releases
3535
type=raw,value=canary,enable=${{contains(env.BRANCH_NAME, 'canary')}}
3636
# tag ci bins releases
3737
type=raw,value=ci-bins,enable=${{contains(env.BRANCH_NAME, 'ci-bins')}}
38-
# if is in MAIN branch, also tag as latest
39-
type=raw,value=latest,enable={{is_default_branch}}
4038
# tag version
4139
type=semver,pattern={{version}}
4240
@@ -53,7 +51,7 @@ jobs:
5351
uses: docker/build-push-action@v6
5452
with:
5553
context: .
56-
file: ./container/for-registry/Containerfile
54+
file: ./container/Containerfile
5755
push: true
5856
tags: ${{ steps.meta.outputs.tags }}
5957
labels: ${{ steps.meta.outputs.labels }}

container/Containerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Built from https://github.com/rust-lang/docker-rust
2+
# Note we specify an explicit version of the image as a workaround for the fact that
3+
# on developer machines "latest" gets pulled once at the beginning of time then never
4+
# updated. So unfortunately we will need to maintain the version here.
5+
FROM rust:1.88 AS builder
6+
7+
# Install build dependencies
8+
RUN apt update && apt install -y build-essential lld pkg-config libssl-dev libgmp-dev clang
9+
10+
WORKDIR /usr/libra
11+
COPY . .
12+
# We specify -j 1 to avoid OOM-killing the build
13+
ARG LIBRA_CARGO_CONCURRENCY=1
14+
RUN cargo build -j $LIBRA_CARGO_CONCURRENCY --release
15+
16+
# Note we specify an explicit version of the image as a workaround for the fact that
17+
# on developer machines "latest" gets pulled once at the beginning of time then never
18+
# updated. So unfortunately we will need to maintain the version here.
19+
FROM ubuntu:24.04
20+
RUN apt update && apt install -y ca-certificates
21+
22+
COPY --from=builder /usr/libra/target/release/libra /usr/libra/target/release/libra-* /usr/local/bin/
23+
24+
COPY container/run.sh /run.sh
25+
COPY container/change-uid.sh /change-uid.sh
26+
27+
# Mount this path to persist node config and storage
28+
VOLUME ["/mnt/libra"]
29+
# Validator p2p port (not used by FN)
30+
EXPOSE 6180/tcp
31+
# VFN p2p port (not used by FN)
32+
EXPOSE 6181/tcp
33+
# FN p2p port (not used by Validators)
34+
EXPOSE 6182/tcp
35+
# API http service
36+
EXPOSE 8080/tcp
37+
38+
SHELL ["/bin/bash", "-c"]
39+
CMD "/run.sh"
40+
CMD ["/change-uid.sh", "/run.sh"]

container/change-uid.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# If USER_UID is not defined we skip everything and run as the default user (usually root)
6+
if [[ ${USER_UID} ]]; then
7+
# If USER_UID set but USER_GID was not set then we set it to the value of USER_UID
8+
if [[ -z ${USER_GID} ]]; then
9+
USER_GID=$USER_UID
10+
fi
11+
# Now we have USER_UID and USER_GID
12+
# Check if USER_UID is 1000
13+
if [[ ${USER_UID} == "1000" ]]; then
14+
# If so we don't need to create a user because the Ubuntu continer already has uid=1000 setup
15+
echo "Running as default user: ubuntu"
16+
else
17+
# We need to change the uid/gid on the ubuntu user
18+
usermod -u $USER_UID ubuntu
19+
groupmod -g $USER_GID ubuntu
20+
echo "Changed uid:gid for user ubuntu to: ${USER_UID}:${USER_GID}"
21+
# Change ownership of the ubuntu user's homedir to the new uid
22+
chown -R ubuntu:ubuntu /home/ubuntu
23+
fi
24+
run_as_ubuntu=1
25+
fi # USER_UID wasn't defined
26+
27+
# Now run the container's workload as either the current user or the ubuntu user
28+
if [[ ${run_as_ubuntu} ]]; then
29+
su - ubuntu -c $1
30+
else
31+
$1
32+
fi

container/for-registry/Containerfile

Lines changed: 0 additions & 15 deletions
This file was deleted.

container/run.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
#
3+
# LIBRA_CONTAINER_MODE : validator|vfn|fullnode
4+
# Currently only supports fullnode mode
5+
6+
# Hack to work around the libra tools not allowing arbitrary config paths
7+
export HOME=/mnt/libra
8+
9+
# Check if this container has already been configured
10+
libra_home=${HOME}/.libra
11+
file_indicating_already_configured="fullnode.yml"
12+
if [[ ! -f ${libra_home}/${file_indicating_already_configured} ]]; then
13+
echo "No existing config detected, initializing as a fullnode..."
14+
# If not, run libra config
15+
libra config fullnode-init --archive-mode false
16+
result=$?
17+
if [[ $result != 0 ]]; then
18+
echo "Fatal Error: libra config failed"
19+
exit 1
20+
fi
21+
echo "Initialized"
22+
else
23+
echo "Container already configured"
24+
fi
25+
# Otherwise fall through to start node
26+
# Start node
27+
echo "Starting libra node"
28+
libra node
File renamed without changes.

container/compose.yaml renamed to testnet/compose.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
services:
22
alice:
33
#image: ubuntu:22.04
4-
image: ghcr.io/0lnetworkcommunity/libra-framework/libra-node:latest
4+
image: ghcr.io/0lnetworkcommunity/libra-node:latest
55
container_name: libra_alice
66
hostname: alice
77
environment:
@@ -17,7 +17,7 @@ services:
1717

1818
bob:
1919
#image: ubuntu:22.04
20-
image: ghcr.io/0lnetworkcommunity/libra-framework/libra-node:latest
20+
image: ghcr.io/0lnetworkcommunity/libra-node:latest
2121
container_name: libra_bob
2222
hostname: bob
2323
depends_on:
@@ -35,7 +35,7 @@ services:
3535

3636
carol:
3737
#image: ubuntu:22.04
38-
image: ghcr.io/0lnetworkcommunity/libra-framework/libra-node:latest
38+
image: ghcr.io/0lnetworkcommunity/libra-node:latest
3939
container_name: libra_carol
4040
hostname: carol
4141
depends_on:
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)