Skip to content

Commit

Permalink
ci: Build using musl on x64, Add dockerfile, workflow to build images (
Browse files Browse the repository at this point in the history
  • Loading branch information
mpwsh authored Jan 27, 2024
1 parent a6afeb9 commit 33dae90
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 42 deletions.
47 changes: 46 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
bin: splash-linux-arm64
- os_name: Linux-x86_64
os: ubuntu-20.04
target: x86_64-unknown-linux-gnu
target: x86_64-unknown-linux-musl
bin: splash-linux-amd64
- os_name: Windows-x86_64
os: windows-latest
Expand All @@ -40,6 +40,9 @@ jobs:
- stable
steps:
- uses: actions/checkout@v3
- name: Install Linux musl-tools
if: contains(matrix.platform.target, 'musl')
run: sudo apt-get install --yes --no-install-recommends musl-tools
- name: Build binary
uses: houseabsolute/actions-rust-cross@v0
with:
Expand All @@ -62,3 +65,45 @@ jobs:
files: |
target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}
target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}.sha256
docker:
runs-on: ubuntu-latest
name: Build and push image
needs: build
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- run: docker context create ci
- run: docker context use ci
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
endpoint: ci
- name: Fetch latest release tag
id: latest-tag
run: |
LATEST_TAG=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name)
echo "Latest release tag is $LATEST_TAG"
echo "::set-output name=tag::$LATEST_TAG"
shell: bash
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/amd64, linux/arm64
build-args: |
GITHUB_ORG=${{ github.repository_owner }}
GITHUB_REPO=${{ github.event.repository.name }}
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ steps.latest-tag.outputs.tag }},${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
53 changes: 17 additions & 36 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ futures = "0.3.30"
libp2p = { version = "0.53.2", features = [ "tokio", "gossipsub", "kad", "noise", "macros", "identify", "tcp", "yamux", "secp256k1", "dns"] }
tracing = "0.1.37"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
env_logger = "0.10.1"
env_logger = "0.11.1"
clap = { version = "4.4.17", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM alpine:3.14

RUN apk add --no-cache curl jq

WORKDIR /app

ARG GITHUB_ORG
ARG GITHUB_REPO
ENV GITHUB_ORG $GITHUB_ORG
ENV GITHUB_REPO $GITHUB_REPO


RUN arch=$(uname -m) && \
os=$(uname -s) && \
case "$arch" in \
x86_64) arch="amd64" ;; \
aarch64) arch="arm64" ;; \
*) echo "Unsupported architecture: $arch" && exit 1 ;; \
esac && \
case "$os" in \
Linux) os="linux" ;; \
Darwin) os="darwin" ;; \
*) echo "Unsupported OS: $os" && exit 1 ;; \
esac && \
RELEASE_URL=$(curl -sfL https://api.github.com/repos/${GITHUB_ORG}/${GITHUB_REPO}/releases/latest | \
jq -r --arg binary "${GITHUB_REPO}-${os}-${arch}" '.assets[] | select(.name == $binary) | .browser_download_url') && \
echo "Downloading binary" && \
curl -sfL ${RELEASE_URL} -o ${GITHUB_REPO} && \
chmod +x ${GITHUB_REPO}

RUN cat > /entrypoint.sh <<'EOF'
#!/bin/sh
exec /app/${GITHUB_REPO} "$@"
EOF

RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ Start a node and reuse identity:

`./splash --identify-file identity.json`

## Test the API with Docker

```bash
docker run -p 11511:11511 -p 4000:4000 dexie-space/splash:latest \
--listen-offer-submission 0.0.0.0:4000 \
--listen-address /ip4/0.0.0.0/tcp/11511
# send the request
curl -X POST -H "Content-Type: application/json" -d '{"offer":"offer1..."}' http://localhost:4000
```

## Become a stable peer

To become a stable peer, you need to open an inbound port in your firewall. Then start Splash! with the `--listen-address` option and choose your public interface and the selected port (eg. `11511`).
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
)?
.with_dns()?
.with_behaviour(|key| {
println!("Our Peer ID: {}", key.public().to_peer_id().to_string());
println!("Our Peer ID: {}", key.public().to_peer_id());

// We can take the hash of message and use it as an ID.
let unique_offer_fn = |message: &gossipsub::Message| {
Expand All @@ -85,9 +85,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
// Create a Kademlia behaviour.
let mut cfg = kad::Config::default();

cfg.set_protocol_names(vec![StreamProtocol::try_from_owned(format!(
"/splash/kad/1"
))?]);
cfg.set_protocol_names(vec![StreamProtocol::try_from_owned(
"/splash/kad/1".to_string(),
)?]);

cfg.set_query_timeout(Duration::from_secs(60));
let store = kad::store::MemoryStore::new(key.public().to_peer_id());
Expand Down

0 comments on commit 33dae90

Please sign in to comment.