Skip to content
Merged
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
22 changes: 20 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ jobs:
|| gh release create "$GITHUB_REF_NAME" --verify-tag --generate-notes $prerelease
gh release upload "$GITHUB_REF_NAME" --clobber berth-*.tar.gz berth-*.tar.gz.sha256 \
berth-*.zip berth-*.zip.sha256 install.sh install.ps1 VERSION
# The image holds the program the release publishes for x86_64, so it is
# built once. Its Dockerfile is the one berth carries to build an image of
# itself on a server.
image:
needs: [binary]
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -164,6 +168,17 @@ jobs:
fi
echo "BERTH_BUILD_VERSION=$version" >> "$GITHUB_ENV"
fi
- uses: actions/download-artifact@v4
with:
name: berth-x86_64-unknown-linux-musl
- name: The context
run: |
mkdir -p build/image
tar -xzf berth-x86_64-linux.tar.gz -C build/image berth
cp provision/requirements.txt build/image/
version=${BERTH_BUILD_VERSION:-$(sed -n '/^\[workspace.package\]/,/^\[/s/^version = "\(.*\)"/\1/p' Cargo.toml)}
echo "BERTH_IMAGE_VERSION=$version" >> "$GITHUB_ENV"
echo "BERTH_IMAGE_SHA256=$(sha256sum build/image/berth | cut -d' ' -f1)" >> "$GITHUB_ENV"
- uses: docker/setup-buildx-action@v4
- uses: docker/login-action@v4
if: github.event_name != 'pull_request'
Expand All @@ -181,9 +196,12 @@ jobs:
type=edge,branch=main
- uses: docker/build-push-action@v6
with:
context: .
context: build/image
file: container/berth.Dockerfile
build-args: BERTH_BUILD_VERSION=${{ env.BERTH_BUILD_VERSION }}
build-args: |
BERTH_VERSION=${{ env.BERTH_IMAGE_VERSION }}
BERTH_SHA256=${{ env.BERTH_IMAGE_SHA256 }}
BERTH_SOURCE=published
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down
43 changes: 27 additions & 16 deletions container/berth.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,19 @@
# client for the Docker plugin. The engine is another machine's, or this
# machine's through its socket.
#
# docker build -f container/berth.Dockerfile -t berth .
# The program is not built here. The context holds a static Linux build of
# it as `berth`, with `requirements.txt` from the provisioning source:
#
# BERTH_BUILD_VERSION is the version a release gives it, from its tag; without
# it the image says the version in Cargo.toml.
# berth server image builds it with this machine's engine
# berth server deploy HOST builds it on HOST and runs the server from it
#
# CI builds the published image from the same file, with the release's own
# program in the context and BERTH_SOURCE=published. berth carries this file
# and a test checks that the two are the same.
#
# Settings and host profiles live in /config, the store and builds in /data.
FROM rust:1-bookworm AS build
RUN apt-get update && apt-get install -y --no-install-recommends musl-tools python3 \
&& rm -rf /var/lib/apt/lists/* \
&& rustup target add x86_64-unknown-linux-musl
WORKDIR /src
COPY . .
ARG BERTH_BUILD_VERSION=
RUN cargo build --release --locked --target x86_64-unknown-linux-musl -p berth \
&& said=$(target/x86_64-unknown-linux-musl/release/berth --version) && echo "$said" \
&& { [ -z "$BERTH_BUILD_VERSION" ] || [ "$said" = "berth $BERTH_BUILD_VERSION" ]; }

FROM debian:trixie-slim
COPY provision/requirements.txt /tmp/requirements.txt
COPY requirements.txt /tmp/requirements.txt
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates curl docker-buildx docker-cli docker-compose npm openssh-client openssl \
python3 python3-pip tar tini \
Expand All @@ -30,7 +24,24 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* /tmp/requirements.txt \
&& useradd --create-home --uid 1000 berth \
&& mkdir -p /config /data && chown berth:berth /config /data
COPY --from=build /src/target/x86_64-unknown-linux-musl/release/berth /usr/local/bin/berth
# The context gives it mode 0755, which COPY keeps.
COPY berth /usr/local/bin/berth
# The version the program has to say, and the SHA-256 it has to have. The
# build stops when either is not so, which also stops a program for another
# CPU, as it does not run here.
ARG BERTH_VERSION=
ARG BERTH_SHA256=
RUN said=$(berth --version) && echo "$said" \
&& case "$said" in "berth $BERTH_VERSION" | "berth $BERTH_VERSION "*) ;; *) [ -z "$BERTH_VERSION" ] ;; esac \
&& { [ -z "$BERTH_SHA256" ] || echo "$BERTH_SHA256 /usr/local/bin/berth" | sha256sum -c -; }
# `self-built` for an image built from a berth, `published` for CI's. The
# baseline is the repository a self-built server goes back to for a release.
ARG BERTH_SOURCE=self-built
ARG BERTH_BASELINE=ghcr.io/helightdev/berth
LABEL org.opencontainers.image.version=$BERTH_VERSION \
dev.berth.source=$BERTH_SOURCE \
dev.berth.baseline=$BERTH_BASELINE \
dev.berth.binary-sha256=$BERTH_SHA256
USER berth
ENV XDG_CONFIG_HOME=/config XDG_DATA_HOME=/data TERM=xterm-256color
VOLUME ["/config", "/data"]
Expand Down
16 changes: 16 additions & 0 deletions crates/berth-api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,22 @@ pub struct Act {
pub rows: Option<u16>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cols: Option<u16>,
/// Bytes for the standard input of an action that takes them, in base64:
/// the build context of a berth for `upgrade-server source=here`. They
/// go over HTTP when they are more than the portal carries.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub input_b64: Option<String>,
}

/// The node's action that runs a berth server in its container from another
/// image, and its argument `source`.
pub mod upgrade_server {
pub const ACTION: &str = "upgrade-server";
pub const SOURCE: &str = "source";
/// The published image of the version.
pub const RELEASE: &str = "release";
/// An image built on the node from the berth that runs the action.
pub const HERE: &str = "here";
}

/// What running an action answers: one of the three.
Expand Down
1 change: 1 addition & 0 deletions crates/berth-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub mod runner;
pub mod seal;
pub mod seed;
pub mod server;
pub mod server_image;
pub mod store;
pub mod tailnet;

Expand Down
Loading
Loading