Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broadcast vanish requests #14

Merged
merged 19 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
85 changes: 85 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: CI Pipeline

on:
push:
branches: ['main']
pull_request:
branches: ['main']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't want to publish new docker images on every pull request commit, or do we?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to, because the integration tests run the full code as compose.yml describes. This way we can have the sh script hit all the complete services using even external tools like nak etc


env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
test:
name: Run Integration Tests
runs-on: ubuntu-latest

steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Set up Docker Buildx
if: ${{ !env.ACT }}
uses: docker/setup-buildx-action@v3

- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
push: false
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Run integration tests
run: |
docker compose up --abort-on-container-exit --exit-code-from tests

- name: Check for test failures
if: failure()
run: |
echo "Tests failed, check the logs for details."

build_and_push:
name: Build and Push Docker image
needs: test
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' && needs.test.result == 'success' }}
permissions:
packages: write
contents: read

steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Log in to the GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
if: ${{ !env.ACT }}
uses: docker/setup-buildx-action@v3

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch,suffix=_{{ github.sha }}
type=raw,value=latest,enable={{ github.ref == 'refs/heads/main' }}

- name: Build and push Docker image. The build was cached
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
45 changes: 0 additions & 45 deletions .github/workflows/publish-docker-image.yml

This file was deleted.

104 changes: 89 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
FROM ubuntu:jammy AS build
# Stage 1: Build
ARG BUILDPLATFORM=linux/amd64

FROM --platform=$BUILDPLATFORM ubuntu:jammy AS build

ARG TARGETPLATFORM
ARG BUILDPLATFORM

WORKDIR /build

RUN apt-get update && apt-get install -y gnupg
RUN apt-key adv --refresh-keys --keyserver keyserver.ubuntu.com

RUN apt update && apt install -y --no-install-recommends \
git g++ make pkg-config libtool ca-certificates \
unzip cmake git g++ make pkg-config libtool ca-certificates \
libyaml-perl libtemplate-perl libregexp-grammars-perl libssl-dev zlib1g-dev \
liblmdb-dev libflatbuffers-dev libsecp256k1-dev libzstd-dev curl build-essential

Expand All @@ -19,32 +28,87 @@ ENV PATH="/root/.cargo/bin:${PATH}"

RUN rustc --version

COPY ./spam_filter/Cargo.toml ./spam_filter/Cargo.lock /build/spam_filter/
COPY ./event_deleter/Cargo.toml ./event_deleter/Cargo.lock /build/event_deleter/
COPY ./event_deleter/src /build/event_deleter/src
WORKDIR /build/event_deleter
RUN cargo fetch
RUN cargo build --release --bins --tests

WORKDIR /build/spam_filter
RUN ls /build/event_deleter
RUN ls /build/event_deleter/target
RUN find /build/event_deleter/target -type d
RUN curl -fsSL https://deno.land/install.sh | sh
ENV DENO_INSTALL="/root/.deno"
ENV PATH="$DENO_INSTALL/bin:$PATH"
RUN echo "Deno is located at: $(which deno)"

RUN cargo fetch
RUN curl -L https://github.com/fiatjaf/nak/releases/download/v0.7.6/nak-v0.7.6-linux-amd64 -o /usr/local/bin/nak && \
chmod +x /usr/local/bin/nak

COPY ./spam_filter/src /build/spam_filter/src
RUN curl -L https://github.com/IBM-Cloud/redli/releases/download/v0.13.0/redli_0.13.0_linux_amd64.tar.gz -o /tmp/redli.tar.gz && \
tar -xvf /tmp/redli.tar.gz -C /usr/local/bin/ redli_linux_amd64 && \
mv /usr/local/bin/redli_linux_amd64 /usr/local/bin/redli && \
chmod +x /usr/local/bin/redli

RUN cargo build --release
RUN nak --version
RUN redli --version

FROM ubuntu:jammy AS runner
# Stage 2: tests
FROM --platform=${BUILDPLATFORM} ubuntu:jammy AS tests

EXPOSE 7777
COPY --from=build /usr/local/bin/nak /usr/local/bin/nak
RUN chmod +x /usr/local/bin/nak

RUN apt update && apt install -y --no-install-recommends \
curl jq git g++ make pkg-config libtool ca-certificates \
libyaml-perl libtemplate-perl libregexp-grammars-perl libssl-dev zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*

COPY ./push_vanish_request.ts /usr/local/bin/push_vanish_request.ts
COPY ./run_integration_tests.sh /usr/local/bin/run_integration_tests.sh

RUN chmod +x /usr/local/bin/push_vanish_request.ts
RUN chmod +x /usr/local/bin/run_integration_tests.sh

COPY --from=build /build/event_deleter/Cargo.toml /tests/event_deleter/
COPY --from=build /build/event_deleter/Cargo.lock /tests/event_deleter/
COPY --from=build /build/event_deleter/src /tests/event_deleter/src
COPY --from=build /build/event_deleter/target /tests/event_deleter/target

COPY --from=build /root/.cargo /root/.cargo
ENV PATH="/root/.cargo/bin:${PATH}"

RUN rustup default stable

COPY ./strfry/plugins/ /tests/strfry/plugins/
COPY ./run_tests.sh /usr/local/bin/run_tests.sh
RUN chmod +x /usr/local/bin/run_tests.sh

WORKDIR /tests

COPY --from=build /root/.deno /root/.deno
ENV PATH="/root/.deno/bin:${PATH}"

RUN deno --version

CMD ["run_tests.sh"]

# Stage 3: runner
FROM --platform=${BUILDPLATFORM} ubuntu:jammy AS runner

RUN apt-get update && apt-get install -y --no-install-recommends \
vim curl unzip ca-certificates \
vim curl jq ca-certificates \
liblmdb0 libflatbuffers1 libsecp256k1-0 libb2-1 libzstd1 \
&& rm -rf /var/lib/apt/lists/*

RUN update-ca-certificates

RUN curl -fsSL https://deno.land/install.sh | sh
ENV DENO_INSTALL="/root/.deno"
ENV PATH="$DENO_INSTALL/bin:$PATH"
COPY --from=build /root/.deno /root/.deno
ENV PATH="/root/.deno/bin:${PATH}"
RUN deno --version

EXPOSE 7777

COPY ./strfry/config/strfry.conf /etc/strfry.conf
RUN mkdir -p /app/strfry-db
COPY ./strfry/plugins/ /app/plugins/
Expand All @@ -53,9 +117,19 @@ RUN chmod +x /app/plugins/policies.ts
WORKDIR /app

COPY --from=build /build/strfry/strfry strfry
COPY --from=build /build/event_deleter/target/release/spam_cleaner /usr/local/bin/spam_cleaner
COPY --from=build /build/event_deleter/target/release/vanish_subscriber ./vanish_subscriber
COPY --from=build /usr/local/bin/nak /usr/local/bin/nak
COPY --from=build /usr/local/bin/redli /usr/local/bin/redli
COPY ./push_vanish_request.ts /app/push_vanish_request.ts

COPY --from=build /build/spam_filter/target/release/spam_cleaner /usr/local/bin/spam_cleaner
RUN chmod +x /app/vanish_subscriber

# Tools
RUN chmod +x /usr/local/bin/nak
RUN chmod +x /usr/local/bin/redli
RUN chmod +x /usr/local/bin/spam_cleaner
RUN chmod +x /app/push_vanish_request.ts

ENTRYPOINT ["/app/strfry", "relay"]
COPY ./start.sh start.sh
CMD ./start.sh
26 changes: 25 additions & 1 deletion compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
services:
nosrelay:
build: .
build:
context: .
dockerfile: Dockerfile
ports:
- "7777:7777"
environment:
- RELAY_URL=wss://example.com
- REDIS_URL=redis://redis:6379
depends_on:
- redis

redis:
image: redis:7.2.4
ports:
- "6379:6379"
command: redis-server --loglevel notice

tests:
build:
context: .
dockerfile: Dockerfile
target: tests
environment:
- RELAY_URL=wss://example.com
- REDIS_URL=redis://redis:6379
depends_on:
- redis
restart: "no"
File renamed without changes.
Loading