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

fix: docker multi platform images #54

Merged
merged 7 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ jobs:

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
# https://github.com/docker/metadata-action/tree/v5/#latest-tag
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch

- name: Build and push
uses: docker/build-push-action@v5
Expand All @@ -44,3 +46,4 @@ jobs:
push: ${{ github.event_name == 'push' || github.event.inputs.push == 'true' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/arm64, linux/amd64
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20-slim as builder
FROM --platform=$BUILDPLATFORM node:20-slim as builder

RUN apt-get update
RUN apt-get install -y build-essential cmake git libssl-dev tini
Expand All @@ -15,7 +15,7 @@ RUN npm run build

RUN npm prune --omit=dev

FROM node:20-slim as app
FROM --platform=$BUILDPLATFORM node:20-slim as app
ENV NODE_ENV production
WORKDIR /app
# built src without dev dependencies
Expand All @@ -27,6 +27,8 @@ COPY --from=builder /usr/bin/tini /usr/bin/tini
COPY --from=builder /usr/lib/**/libcrypto* /usr/lib/
COPY --from=builder /usr/lib/**/libssl* /usr/lib/

EXPOSE 8080

HEALTHCHECK --interval=12s --timeout=12s --start-period=10s CMD npm run healthcheck

# Use tini to handle signals properly, see https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#handling-kernel-signals
Expand Down
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ Docker images for Helia.

This container image hosts helia in a node container. It implements [HTTP IPFS-gateway API](https://docs.ipfs.tech/concepts/ipfs-gateway/#gateway-types) and responds to the incoming requests using helia to fetch the content from IPFS.

## Run from the github container registry

```sh
$ docker run -it -p 8080:8080 ghcr.io/ipfs/helia-http-gateway:main
```

See https://github.com/ipfs/helia-http-gateway/pkgs/container/helia-http-gateway for more information.

## Run Using Docker Compose

```sh
Expand All @@ -16,19 +24,19 @@ $ docker-compose up

### Build
```sh
$ docker build . --tag helia
$ docker build . --tag helia-http-gateway:local
```

Pass the explicit platform when building on a Mac.

```sh
$ docker build . --tag helia --platform linux/arm64
$ docker build . --platform linux/arm64 --tag helia-http-gateway:local-arm64
```

### Running

```sh
$ docker run -it -p 8080:8080 -e DEBUG="helia-http-gateway" helia
$ docker run -it -p 8080:8080 -e DEBUG="helia-http-gateway*" helia-http-gateway:local # or helia-http-gateway:local-arm64
```

## Supported Environment Variables
Expand All @@ -39,7 +47,7 @@ $ docker run -it -p 8080:8080 -e DEBUG="helia-http-gateway" helia
| `FASTIFY_DEBUG` | Debug level for fastify's logger | `''`|
| `PORT` | Port to listen on | `8080` |
| `HOST` | Host to listen on | `0.0.0.0` |
| `USE_SUBDOMAINS` | Whether to use [origin isolation](https://docs.ipfs.tech/how-to/gateway-best-practices/#use-subdomain-gateway-resolution-for-origin-isolation) | `false` |
| `USE_SUBDOMAINS` | Whether to use [origin isolation](https://docs.ipfs.tech/how-to/gateway-best-practices/#use-subdomain-gateway-resolution-for-origin-isolation) | `true` |
| `METRICS` | Whether to enable prometheus metrics. Any value other than 'true' will disable metrics. | `true` |
| `USE_BITSWAP` | Use bitswap to fetch content from IPFS | `true` |
| `USE_TRUSTLESS_GATEWAYS` | Whether to fetch content from trustless-gateways or not | `true` |
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const HOST = process.env.HOST ?? '0.0.0.0'
export const DEBUG = process.env.DEBUG ?? ''
export const FASTIFY_DEBUG = process.env.FASTIFY_DEBUG ?? ''

export const USE_SUBDOMAINS = process.env.USE_SUBDOMAINS === 'true'
export const USE_SUBDOMAINS = process.env.USE_SUBDOMAINS !== 'false'

export const RESOLVE_REDIRECTS = process.env.RESOLVE_REDIRECTS !== 'false'

Expand Down