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

Docker image improvements #655

Closed
wants to merge 5 commits into from
Closed
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
4 changes: 4 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v1
with:
Expand All @@ -39,6 +42,7 @@ jobs:
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
31 changes: 26 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
FROM docker.io/node:alpine as builder
FROM --platform=${BUILDPLATFORM} docker.io/library/node:16.13-alpine3.15 as builder
RUN apk add --no-cache git python3 build-base
COPY . /app
WORKDIR /app
RUN yarn install \
&& yarn build

FROM docker.io/nginx:alpine
# Install the dependencies first
COPY yarn.lock package.json ./
RUN yarn install

# Copy the rest and build the app
COPY . .
RUN yarn build

# Remove the default config, replace it with a symlink to somewhere that will be updated at runtime
RUN rm -f target/config.json \
&& ln -sf /tmp/config.json target/config.json

FROM --platform=${TARGETPLATFORM} docker.io/nginxinc/nginx-unprivileged:1.21-alpine

# Copy the config template as well as the templating script
COPY ./docker/config.json.tmpl /config.json.tmpl
COPY ./docker/config-template.sh /docker-entrypoint.d/99-config-template.sh

# Copy the built app from the first build stage
COPY --from=builder /app/target /usr/share/nginx/html

# Values from the default config that can be overridden at runtime
ENV PUSH_APP_ID="io.element.hydrogen.web" \
PUSH_GATEWAY_URL="https://matrix.org" \
PUSH_APPLICATION_SERVER_KEY="BC-gpSdVHEXhvHSHS0AzzWrQoukv2BE7KzpoPO_FfPacqOo3l1pdqz7rSgmB04pZCWaHPz7XRe6fjLaC-WPDopM" \
DEFAULT_HOMESERVER="matrix.org"
12 changes: 7 additions & 5 deletions doc/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ To stop the container, simply hit `ctrl+c`.

In this repository, create a Docker image:

```
```sh
# Enable BuildKit https://docs.docker.com/develop/develop-images/build_enhancements/
export DOCKER_BUILDKIT=1
docker build -t hydrogen .
```

Or, pull the docker image from GitLab:
Or, pull the Docker image the GitHub Container Registry:

```
docker pull registry.gitlab.com/jcgruenhage/hydrogen-web
docker tag registry.gitlab.com/jcgruenhage/hydrogen-web hydrogen
docker pull ghcr.io/vector-im/hydrogen
docker tag ghcr.io/vector-im/hydrogen hydrogen
```

### Start container image
Expand All @@ -53,6 +55,6 @@ Then, start up a container from that image:
```
docker run \
--name hydrogen \
--publish 80:80 \
--publish 8080:80 \
hydrogen
```
7 changes: 7 additions & 0 deletions docker/config-template.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

set -eux

envsubst '$PUSH_APP_ID,$PUSH_GATEWAY_URL,$PUSH_APPLICATION_SERVER_KEY,$DEFAULT_HOMESERVER' \
< /config.json.tmpl \
> /tmp/config.json
8 changes: 8 additions & 0 deletions docker/config.json.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"push": {
"appId": "$PUSH_APP_ID",
"gatewayUrl": "$PUSH_GATEWAY_URL",
"applicationServerKey": "$PUSH_APPLICATION_SERVER_KEY"
},
"defaultHomeServer": "$DEFAULT_HOMESERVER"
}