Skip to content

Commit

Permalink
36: release packaging for ghcr container registry
Browse files Browse the repository at this point in the history
  • Loading branch information
jac18281828 committed Jan 19, 2024
1 parent 7f93c79 commit f7b65b5
Show file tree
Hide file tree
Showing 12 changed files with 316 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
push:
branches:
- "*"

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -25,6 +25,8 @@ jobs:

- name: Build and Push
uses: docker/build-push-action@v3
env:
CARGO_INCREMENTAL: 0
with:
context: .
platforms: linux/amd64
Expand Down
63 changes: 63 additions & 0 deletions .github/workflows/ghcr-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Docker Image Build Push

on:
push:
tags:
- "*"

concurrency:
group: "docker-image"
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Generate repository name
run: |
echo "REPOSITORY_PATH=$( echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]' )" >> ${GITHUB_ENV}
echo "REPOSITORY_SHA=$( echo ${GITHUB_SHA} | cut -c 1-8 )" >> ${GITHUB_ENV}
-
name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and Push
uses: docker/build-push-action@v3
env:
CARGO_INCREMENTAL: 0
with:
context: .
file: ./prod/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
build-args: |
VERSION=${{ github.ref_name }}
tags: |
ghcr.io/${{ env.REPOSITORY_PATH }}:v${{ github.ref_name }}
ghcr.io/${{ env.REPOSITORY_PATH }}:${{ env.REPOSITORY_SHA }}
ghcr.io/${{ env.REPOSITORY_PATH }}:latest
-
name: GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
draft: false
prerelease: false
tag_name: ${{ github.ref_name }}
release_name: v${{ github.ref_name }}
body_path: CHANGELOG.md
2 changes: 2 additions & 0 deletions .github/workflows/github-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:
override: true

- name: Run tests
env:
CARGO_INCREMENTAL: 0
run: |
cargo test
id: test
Expand Down
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@
}
}
]
}
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 0.1.0 (2024-01-19)

* initial release image
107 changes: 107 additions & 0 deletions Cargo.lock

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

15 changes: 9 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ COPY --chown=xmtp:xmtp . .
ENV PATH=~xmtp/.cargo/bin:$PATH
ENV USER=xmtp

RUN ~xmtp/.cargo/bin/cargo check
RUN ~xmtp/.cargo/bin/cargo fmt --check
RUN ~xmtp/.cargo/bin/cargo clippy --all-features --no-deps -- -D warnings
RUN ~xmtp/.cargo/bin/cargo test
RUN cargo check
RUN cargo fmt --check
RUN cargo clippy --all-features --no-deps -- -D warnings
RUN cargo test
RUN cargo build --release
RUN CARGO_TARGET_DIR=/workspaces/${PROJECT}/target cargo install --path xps-gateway --bin=xps_gateway
RUN valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose ${HOME}/.cargo/bin/xps_gateway --help

LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="rustdev" \
org.label-schema.description="Rust Development Container" \
org.label-schema.url="https://github.com/xmtp/gateway" \
org.label-schema.url="https://github.com/xmtp/xps-gateway" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="git@github.com:xmtp/gateway.git" \
org.label-schema.vcs-url="git@github.com:xmtp/xps-gateway.git" \
org.label-schema.vendor="xmtp" \
org.label-schema.version=$VERSION \
org.label-schema.schema-version="1.0" \
Expand Down
57 changes: 57 additions & 0 deletions prod/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
FROM ghcr.io/xmtp/rust:latest as builder

USER xmtp

RUN sudo apt update && sudo apt install -y pkg-config openssl libssl-dev

RUN sudo mkdir -p /xmtp
RUN sudo chown -R xmtp:xmtp /xmtp

WORKDIR /build
COPY --chown=xmtp:xmtp . .

ENV PATH=~xmtp/.cargo/bin:$PATH
ENV USER=xmtp

RUN cargo check
RUN cargo fmt --check
RUN cargo clippy --all-features --no-deps -- -D warnings
RUN cargo test
RUN cargo build --release
RUN CARGO_TARGET_DIR=/build/target cargo install --root /xmtp --path xps-gateway --bin=xps_gateway
RUN strip /xmtp/bin/xps_gateway
RUN cp CHANGELOG.md /xmtp/
RUN cp LICENSE /xmtp/

FROM debian:stable-slim
ARG TARGETARCH

RUN export DEBIAN_FRONTEND=noninteractive && \
apt update && \
apt install -y -q --no-install-recommends \
ca-certificates apt-transport-https \
&& \
apt clean && \
rm -rf /var/lib/apt/lists/*

COPY --from=builder /xmtp/ /xmtp/

RUN useradd -s /dev/null none

EXPOSE 8080

ENV USER=none
USER none

CMD ["/xmtp/bin/xps_gateway", "--host", "0.0.0.0", "--port", "8080"]

LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="xps-gateway" \
org.label-schema.description="xps-gateway" \
org.label-schema.url="https://github.com/xmtp/xps-gateway" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="git@github.com:xmtp/xps-gateway.git" \
org.label-schema.vendor="xmtp" \
org.label-schema.version=$VERSION \
org.label-schema.schema-version="1.0" \
org.opencontainers.image.description="XPS-Gateway Container"
1 change: 1 addition & 0 deletions xps-gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jsonrpsee = { version = "0.21", features = ["macros", "server", "client-core"] }
anyhow = "1"
thiserror = "1"
ctor = "0.2"
clap = { version = "4.4.18", features = ["derive"] }

[dev-dependencies]
jsonrpsee = { version = "0.21", features = ["macros", "server", "client"] }
Expand Down
8 changes: 4 additions & 4 deletions xps-gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use jsonrpsee::server::Server;

pub use crate::rpc::{XpsMethods, XpsServer};

pub const SERVER_HOST: &str = "127.0.0.1:0";

/// Entrypoint for the xps Gateway
pub async fn run() -> Result<()> {
pub async fn run(host: String, port: u16) -> Result<()> {

Check warning on line 11 in xps-gateway/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

xps-gateway/src/lib.rs#L11

Added line #L11 was not covered by tests
crate::util::init_logging();

let server_addr = format!("{}:{}", host, port);

Check warning on line 14 in xps-gateway/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

xps-gateway/src/lib.rs#L14

Added line #L14 was not covered by tests

// a port of 0 allows the OS to choose an open port
let server = Server::builder().build(SERVER_HOST).await?;
let server = Server::builder().build(server_addr).await?;

Check warning on line 17 in xps-gateway/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

xps-gateway/src/lib.rs#L17

Added line #L17 was not covered by tests
let addr = server.local_addr()?;
let handle = server.start(rpc::XpsMethods.into_rpc());

Expand Down
Loading

0 comments on commit f7b65b5

Please sign in to comment.