Skip to content

Commit

Permalink
refactor: docker updates with info command and rpc host update (#558)
Browse files Browse the repository at this point in the history
Includes:
- macos-14 for checks on ci
- some doc changes
- action-validator in flake for validation when changing github action
workflows
- added timestamp (commit) for `info` command
- fixed some nixy things
  • Loading branch information
Zeeshan Lakhani authored Feb 7, 2024
1 parent 62110f9 commit 706c26d
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 36 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ jobs:
id: crate-version
run: echo version=$(cargo get workspace.package.version)-rc.$(date +%s) >> $GITHUB_OUTPUT

- name: Set Env
run: |
echo "GIT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "GIT_TIMESTAMP=$(git log -1 --pretty=format:'%cI')" >> $GITHUB_ENV
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
Expand Down Expand Up @@ -373,6 +378,9 @@ jobs:
file: docker/Dockerfile
context: .
platforms: linux/amd64,linux/arm64
build-args: |
git_sha=${{ env.GIT_SHA }}
git_timestamp=${{ env.GIT_TIMESTAMP }}
push: true
tags: ${{ steps.meta-release.outputs.tags }}
labels: ${{ steps.meta-release.outputs.labels }}
Expand All @@ -386,6 +394,9 @@ jobs:
file: docker/Dockerfile
context: .
platforms: linux/amd64,linux/arm64
build-args: |
git_sha=${{ env.GIT_SHA }}
git_timestamp=${{ env.GIT_TIMESTAMP }}
push: true
tags: ${{ steps.meta-dispatch.outputs.tags }}
labels: ${{ steps.meta-dispatch.outputs.labels }}
10 changes: 9 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: 🐳 Docker

on:
schedule:
- cron: '0 */4 * * *'
- cron: "0 */4 * * *"

jobs:
build-docker:
Expand All @@ -15,6 +15,11 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set Env
run: |
echo "GIT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "GIT_TIMESTAMP=$(git log -1 --pretty=format:'%cI')" >> $GITHUB_ENV
# https://github.com/docker/setup-qemu-action
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -33,6 +38,9 @@ jobs:
file: docker/Dockerfile
context: .
platforms: linux/amd64
build-args: |
git_sha=${{ env.GIT_SHA }}
git_timestamp=${{ env.GIT_TIMESTAMP }}
push: false
tags: |
${{ github.repository_owner }}/homestar:latest
6 changes: 4 additions & 2 deletions .github/workflows/tests_and_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-14, windows-latest]
rust-toolchain: [stable, nightly, 1.73.0]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:

- name: Run Linter
run: cargo clippy --all -- -D warnings
continue-on-error: ${{ matrix.rust-toolchain == 'nightly' && matrix.os == 'macos-latest' }}
continue-on-error: ${{ matrix.rust-toolchain == 'nightly' && matrix.os == 'macos-14' }}

- name: Install cargo-hakari
if: ${{ matrix.rust-toolchain == 'stable' }}
Expand Down Expand Up @@ -205,6 +205,7 @@ jobs:
- name: Run Doc Tests
if: ${{ matrix.default-features == 'all' }}
run: cargo test --doc --workspace
continue-on-error: ${{ matrix.rust-toolchain == 'nightly' }}

run-tests-windows:
needs: changes
Expand Down Expand Up @@ -258,6 +259,7 @@ jobs:
- name: Run Doc Tests
if: ${{ matrix.default-features == 'all' }}
run: cargo test --doc --workspace
continue-on-error: ${{ matrix.rust-toolchain == 'nightly' }}

run-cargo-tests:
needs: changes
Expand Down
6 changes: 4 additions & 2 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ with `experimental` and `buildkit` set to `true`, for example:
- Build a multi-plaform Docker image via [buildx][buildx]:

```console
docker buildx build --file docker/Dockerfile --platform=linux/amd64,linux/arm64 -t homestar --progress=plain .
docker buildx build --build-arg git_sha=$(git rev-parse HEAD) \
--build-arg git_timestamp=$(git log -1 --pretty=format:'%cI') \
--file docker/Dockerfile --platform=linux/amd64,linux/arm64 -t homestar --progress=plain .
```

- Run a Docker image (depending on your platform):

```console
docker run --platform=linux/arm64 -t homestar
docker run -it --rm --platform=linux/arm64 -p 3030:3030 -p 1337:1337 -t homestar
```

## Nix
Expand Down
13 changes: 10 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ ARG TARGETARCH
FROM builder-$TARGETARCH as builder

ARG database_url="homestar.db"
ARG git_sha
ARG git_timestamp

ENV DATABASE_URL=${database_url}
ENV VERGEN_GIT_SHA=${git_sha}
ENV VERGEN_GIT_COMMIT_TIMESTAMP=${git_timestamp}

RUN adduser --disabled-password --disabled-login --gecos "" --no-create-home homestar

RUN apt install -y git

RUN cargo init
RUN rm -Rf src

Expand All @@ -27,7 +34,7 @@ RUN echo "fn main() {}" > ./homestar-runtime/src/main.rs
RUN mkdir -p ./homestar-runtime/src/test_utils/proc_macro ./homestar-runtime/migrations ./examples ./homestar-functions
RUN bash -c 'pushd ./examples && cargo init dummy-app-examples && popd'
RUN bash -c 'pushd ./homestar-functions && cargo init dummy-app-fns && popd'
RUN cargo init homestar-workspace-hack
RUN cargo init --lib homestar-workspace-hack

# copy cargo.*
COPY Cargo.lock Cargo.toml diesel.toml ./
Expand Down Expand Up @@ -90,7 +97,7 @@ COPY --chown=homestar:homestar --from=builder /etc/*.db ./
COPY --chown=homestar:homestar --from=builder /etc/config ./config

ARG database_url="homestar.db"
ARG rpc_host="127.0.0.1"
ARG rpc_host="0.0.0.0"
ARG rpc_port=3030
ARG ws_port=1337

Expand All @@ -101,4 +108,4 @@ ENV DATABASE_URL=${database_url} \

EXPOSE ${rpc_port} ${ws_port}

ENTRYPOINT ["./homestar", "start", "--db", "homestar.db"]
ENTRYPOINT ["./homestar", "start", "--db", "homestar.db", "-c", "./config/settings.toml"]
42 changes: 21 additions & 21 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@
dockerBuild = arch:
pkgs.writeScriptBin "docker-${arch}" ''
#!${pkgs.stdenv.shell}
docker buildx build --file docker/Dockerfile --platform=linux/${arch} -t homestar-runtime --progress=plain .
docker buildx build --build-arg git_sha=$(git rev-parse HEAD) \
--build-arg git_timestamp=$(git log -1 --pretty=format:'%cI') \
--file docker/Dockerfile --platform=linux/${arch} -t homestar --progress=plain .
'';

xFunc = cmd:
Expand Down Expand Up @@ -240,7 +242,7 @@

testCleanup = pkgs.writeScriptBin "test-clean" ''
#!${pkgs.stdenv.shell}
rm -rf homestar-runtime/tests/fixtures/*.db
rm -rf homestar-runtime/tests/fixtures/*.db*
rm -rf homestar-runtime/tests/fixtures/*.toml
'';

Expand Down Expand Up @@ -289,6 +291,7 @@
direnv
unstable.nodejs_20
unstable.nodePackages.pnpm
action-validator
kubo
self.packages.${system}.irust
]
Expand All @@ -312,6 +315,8 @@
ipfs --repo-dir ./.ipfs --offline init
fi
unset SOURCE_DATE_EPOCH
# Run Kubo / IPFS
echo -e "To run Kubo as a local IPFS node, use the following command:"
echo -e "ipfs --repo-dir ./.ipfs --offline daemon"
Expand Down
3 changes: 1 addition & 2 deletions homestar-runtime/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-changed=migrations");

vergen::EmitBuilder::builder()
.fail_on_error()
.use_local_build()
.git_sha(true)
.git_commit_timestamp()
.cargo_features()
.emit()?;

Expand Down
9 changes: 9 additions & 0 deletions homestar-runtime/config/settings.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[node]

[node.network.libp2p]
listen_address = "/ip4/0.0.0.0/tcp/0"

[node.network.metrics]
port = 4000

[node.network.rpc]
port = 3030

[node.network.webserver]
port = 1337
6 changes: 4 additions & 2 deletions homestar-runtime/src/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ pub(crate) use event::Event;

type P2PSender = channel::AsyncChannelSender<ResponseEvent>;

/// Quorum configuration specifies the minimum number of distinct nodes that
/// must be successfully contacted in order for a query to succeed.
struct Quorum {
/// Minimum number of peers required to receive a receipt.
/// Minimum number of peers required to achieve quorum for a receipt.
receipt: usize,
/// Minimum number of peers required to receive workflow information.
/// Minimum number of peers required to achieve quorum for workflow information.
workflow: usize,
}

Expand Down
8 changes: 7 additions & 1 deletion homestar-runtime/src/runner/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ impl show::ConsoleTable for AckNodeInfo {
pub struct Info {
version: String,
git_sha: String,
timestamp: String,
features: String,
}

Expand All @@ -236,7 +237,12 @@ impl Info {
pub(crate) fn new() -> Self {
Self {
version: env!("CARGO_PKG_VERSION").to_string(),
git_sha: env!("VERGEN_GIT_SHA").to_string(),
git_sha: option_env!("VERGEN_GIT_SHA")
.unwrap_or("unknown")
.to_string(),
timestamp: option_env!("VERGEN_GIT_COMMIT_TIMESTAMP")
.unwrap_or("unknown")
.to_string(),
features: env!("VERGEN_CARGO_FEATURES").to_string(),
}
}
Expand Down

0 comments on commit 706c26d

Please sign in to comment.