Skip to content

Commit

Permalink
[LAB-590] build backend container with private IPFS support (#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
alabdao committed Oct 13, 2023
1 parent 46bb1e5 commit 3744e91
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 15 deletions.
32 changes: 24 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ jobs:
go:
strategy:
matrix:
os: [ubuntu-22.04] # , macos-13]
os:
- ubuntu-22.04
# - macos-13
runs-on: ${{ matrix.os }}
environment: ci
steps:
Expand Down Expand Up @@ -77,7 +79,9 @@ jobs:
ci-setup-ipfs:
strategy:
matrix:
os: [ubuntu-22.04] # , macos-13]
os:
- ubuntu-22.04
# - macos-13
runs-on: ${{ matrix.os }}
environment: ci
steps:
Expand All @@ -102,8 +106,12 @@ jobs:
ci-setup-bacalhau:
strategy:
matrix:
os: [ubuntu-22.04]
bacalhau_version: [1.0.3, 1.1.0]
os:
- ubuntu-22.04
# - macos-13
bacalhau_version:
- 1.0.3
- 1.1.0
runs-on: ${{ matrix.os }}
environment: ci
steps:
Expand All @@ -130,8 +138,12 @@ jobs:
- ci-setup-bacalhau
strategy:
matrix:
os: [ubuntu-22.04] # , macos-13]
bacalhau_version: [1.0.3, 1.1.0]
os:
- ubuntu-22.04
# - macos-13
bacalhau_version:
- 1.0.3
- 1.1.0
runs-on: ${{ matrix.os }}
environment: ci
env:
Expand Down Expand Up @@ -263,8 +275,12 @@ jobs:
- ci-setup-bacalhau
strategy:
matrix:
os: [ubuntu-22.04] # , macos-13]
bacalhau_version: [1.0.3, 1.1.0]
os:
- ubuntu-22.04
# - macos-13
bacalhau_version:
- 1.0.3
- 1.1.0
runs-on: ${{ matrix.os }}
environment: ci
env:
Expand Down
42 changes: 39 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,61 @@
FROM golang:1.20 as builder
FROM golang:1.20-buster as builder

# Install deps
RUN apt-get update && apt-get install -y \
libssl-dev \
ca-certificates \
fuse

COPY . /app/
RUN cd /app/ \
&& CGO_ENABLED=0 go build -o /go/bin/plex

RUN apt-get update && apt-get -y install ca-certificates

FROM alpine
FROM busybox:1.31.1-glibc

COPY --from=builder /go/bin/plex /plex
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /app/gateway/migrations /gateway/migrations

# Copy custom IPFS binary with s3ds and healthcheck plugin
COPY --from=quay.io/labdao/ipfs@sha256:461646b6ea97dffc86b1816380360be3d38d5a2c6c7c86352a2e3b0a5a4ccca5 /usr/local/bin/ipfs /usr/local/bin/ipfs

# Copy init script from ipfs image
COPY --from=quay.io/labdao/ipfs@sha256:461646b6ea97dffc86b1816380360be3d38d5a2c6c7c86352a2e3b0a5a4ccca5 /usr/local/bin/container_init_run /usr/local/bin/container_init_run

# Copy container-init
COPY docker/images/ipfs/container-init.d /container-init.d

# init.d script IPFS runs before starting the daemon. Used to manipulate the IPFS config file.
COPY docker/images/backend/docker-entrypoint.sh /docker-entrypoint.sh

# Copy jq
COPY --from=ghcr.io/jqlang/jq /jq /usr/local/bin/jq

# This shared lib (part of glibc) doesn't seem to be included with busybox.
COPY --from=builder /lib/*-linux-gnu*/libdl.so.2 /lib/

# Copy over SSL libraries.
COPY --from=builder /usr/lib/*-linux-gnu*/libssl.so* /usr/lib/
COPY --from=builder /usr/lib/*-linux-gnu*/libcrypto.so* /usr/lib/

RUN chmod +x /docker-entrypoint.sh

RUN mkdir -p /data/ipfs

ENV POSTGRES_PASSWORD=MAKE_UP_SOMETHING_RANDOM
ENV POSTGRES_USER=labdao
ENV POSTGRES_DB=labdao
ENV POSTGRES_HOST=localhost
ENV FRONTEND_URL=http://localhost:3080
ENV BACALHAU_API_HOST=127.0.0.1
ENV IPFS_PATH=/data/ipfs
ENV IPFS_PROFILE=server
ENV BACALHAU_SERVE_IPFS_PATH=/data/ipfs

EXPOSE 8080

ENTRYPOINT ["/plex"]
ENTRYPOINT ["/docker-entrypoint.sh"]

CMD ["web"]
10 changes: 6 additions & 4 deletions docker-compose.private.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ services:

backend:
environment:
IPFS_PATH: "/data/ipfs"
BACALHAU_SERVE_IPFS_PATH: "/data/ipfs"
BACALHAU_IPFS_SWARM_ADDRESSES: "/dns4/ipfs/tcp/4001/p2p/12D3KooWLpoHJCGxxKozRaUK1e1m2ocyVPB9dzbsU2cydujYBCD7"
volumes:
- ./docker/ipfs_data:/data/ipfs/
IPFS_S3_ENABLED: "false"
IPFS_SWARM_KEY_BASE64: "L2tleS9zd2FybS9wc2svMS4wLjAvCi9iYXNlMTYvCjk0Y2Y4ODFiMDZmZDI5YTgxNDVlMmY2MjNiMmRjNGMwNTU2Y2QxNTIwNWM4YjhjMzg0YWEzOThkY2U4YWFhMzYK"
PRIVATE_IPFS: "true"
LIBP2P_FORCE_PNET: "1"
IPFS_DEBUG: "true"
IPFS_LOGGING: "debug"

volumes:
privateipfs:
19 changes: 19 additions & 0 deletions docker/images/backend/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh
set -e

repo="$IPFS_PATH"

ipfs version

if [ -e "$repo/config" ]; then
echo "Found IPFS fs-repo at $repo"
else
ipfs init ${IPFS_PROFILE:+"--profile=$IPFS_PROFILE"}
ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080
fi


find /container-init.d -maxdepth 1 -type f -iname '*.sh' -print0 | sort -z | xargs -n 1 -0 -r container_init_run

exec /plex "$@"

0 comments on commit 3744e91

Please sign in to comment.