From fb06e25f95ce50a99a07c4f16847582cdcca5413 Mon Sep 17 00:00:00 2001 From: Esteban Borai Date: Sun, 4 Feb 2024 14:09:19 -0300 Subject: [PATCH] chore(docker): publish docker image --- .github/workflows/publish-docker.yml | 58 ++++++++++++++++++++++++++++ Cargo.toml | 3 +- Dockerfile | 7 ++++ Justfile | 14 +++++++ crates/test/Cargo.toml | 3 +- 5 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/publish-docker.yml create mode 100644 Dockerfile diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml new file mode 100644 index 0000000..d791279 --- /dev/null +++ b/.github/workflows/publish-docker.yml @@ -0,0 +1,58 @@ +name: Publish Docker Image + +on: + push: + +concurrency: + group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}" + cancel-in-progress: true + +env: + IMAGE_NAME: commune + GHCR_REGISTRY: ghcr.io/commune-os + +jobs: + publish_image: + name: Publish image + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + id-token: write + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Rust Toolchain + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + targets: x86_64-unknown-linux-musl + + - name: Setup Rust Cache + uses: Swatinem/rust-cache@v2 + + - name: Setup Rust Target + run: rustup target add x86_64-unknown-linux-musl + + - name: Install Build Dependencies + run: | + sudo apt-get update + sudo apt-get install \ + build-essential \ + librust-openssl-dev \ + pkg-config \ + openssl \ + libssl-dev + + - name: Setup Zig + uses: goto-bus-stop/setup-zig@v2.2.0 + + - name: Install ZigBuild + run: cargo install cargo-zigbuild + + - name: Install Just + uses: extractions/setup-just@v1 + + - name: Build Image + run: just docker_build_image diff --git a/Cargo.toml b/Cargo.toml index ba38dff..b5834a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,8 @@ anyhow = "1.0.75" axum = { version = "0.7.4", features = ["tokio"] } dotenv = "0.15.0" http = "0.2.11" -reqwest = "0.11.22" +reqwest = { version = "0.11.22", default-features = false, features = ["blocking", "json", "rustls", "stream", "multipart"] } +openssl = { version = "0.10.63", features = ["vendored"] } serde = "1.0.192" serde_json = "1.0.108" tokio = "1.34.0" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e2bc5c4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM arm64v8/alpine:3 + +COPY server /opt/commune + +WORKDIR app + +ENTRYPOINT ["/opt/commune"] diff --git a/Justfile b/Justfile index e8482e7..736ba2f 100644 --- a/Justfile +++ b/Justfile @@ -1,5 +1,8 @@ set positional-arguments +commit_sha := `git rev-parse --verify HEAD` +target_release := "x86_64-unknown-linux-musl" + # Lists all available commands default: just --list @@ -60,3 +63,14 @@ clear: stop # Runs all the tests from the `test` package. Optionally runs a single one if name pattern is provided e2e *args='': cargo test --package test -- --nocapture --test-threads=1 $1 + +# Builds the Server binary used in the Docker Image +docker_build_server: + cargo zigbuild --target {{target_release}} --release -p server + +# Builds the Docker image for the backend +docker_build_image: docker_build_server + mkdir tmp/ + cp ./target/{{target_release}}/release/server ./tmp/server + chmod +x ./tmp/server + docker build -t "commune:{{commit_sha}}-{{target_release}}" --build-arg . diff --git a/crates/test/Cargo.toml b/crates/test/Cargo.toml index ac3a9f5..6ed384b 100644 --- a/crates/test/Cargo.toml +++ b/crates/test/Cargo.toml @@ -16,7 +16,8 @@ scraper = "0.18.1" anyhow = { workspace = true } axum = { workspace = true, features = ["tokio"] } dotenv = { workspace = true } -reqwest = { workspace = true, features = ["json", "stream", "multipart"] } +reqwest = { workspace = true } +openssl = { workspace = true, features = ["vendored"] } serde = { workspace = true } tokio = { workspace = true, features = ["rt", "rt-multi-thread", "macros"] } url = { workspace = true }