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 based build #4415

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
38 changes: 38 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
ARG VARIANT=20-bookworm-slim
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we are using puppeteer for e2e tests I would recommend a base image that already has chrome and node like:
https://pptr.dev/guides/docker
And avoid all these complexity of installing chrome etc.


FROM --platform=linux/amd64 node:${VARIANT}
LABEL org.opencontainers.image.source="https://github.com/maplibre/maplibre-gl-js"

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install \
--no-install-recommends \
build-essential \
git \
libglew-dev \
libxi-dev \
default-jre \
default-jdk \
xvfb \
python3 \
python-is-python3 \
pkg-config \
libpixman-1-dev \
libcairo2-dev \
libpango1.0-dev \
libgif-dev \
wget \
&& rm -rf /var/lib/apt/lists/*

# For testing purposes
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub > linux_signing_key.pub \
&& install -D -o root -g root -m 644 linux_signing_key.pub /etc/apt/keyrings/linux_signing_key.pub \
&& echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/linux_signing_key.pub] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list \
&& apt -y update && export DEBIAN_FRONTEND=noninteractive \
&& apt -y install google-chrome-stable \
&& rm -rf /var/lib/apt/lists/*

COPY ./ /maplibre-gl-js/
WORKDIR /maplibre-gl-js
RUN npm ci && npm run build-dist
CMD npm run start
EXPOSE 9966
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "MapLibre container using node.js",
"build": { "dockerfile": "Dockerfile" },
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would assume that using a docker image would avoid the need for all the below installations.
Also, if we publish an image as part of the commits to main I would expect to be able to use this image for codespaces...?

"postCreateCommand": "/bin/bash -l -c \"source $NVM_DIR/nvm.sh && nvm install && npm install && echo 'done npm install' && sudo apt-get update && sudo apt-get install -y build-essential git libglew-dev libxi-dev default-jre default-jdk xvfb\""
}
20 changes: 20 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@ on:
workflow_dispatch:

jobs:
push-dev-image:
runs-on: ubuntu-latest
defaults:
run:
working-directory: './devcontainer'
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@main
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better to use a version, like in other places in the CI.

Copy link
Author

Choose a reason for hiding this comment

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

Better to use a version, like in other places in the CI.

OK. So I used this:

ghcr.io/maplibre/maplibre-gl-js:${{ steps.package-version.outputs.current-version }}

Copy link
Collaborator

Choose a reason for hiding this comment

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

I meant v4 or so for the checkout action...


- name: 'Login to GitHub Container Registry'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

- name: 'Build Inventory Image'
run: |
docker build . --tag ghcr.io/maplibre/maplibre-gl-js:${{ steps.package-version.outputs.current-version }}
docker push ghcr.io/maplibre/maplibre-gl-js:${{ steps.package-version.outputs.current-version }}
release-check:
name: Check if version changed
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### ✨ Features and improvements

- Expose projection matrix parameters ([#3136](https://github.com/maplibre/maplibre-gl-js/pull/3136))
- Add docker build abilities ([#57](https://github.com/maplibre/maplibre-gl-js/issues/57))
- _...Add new stuff here..._

### 🐞 Bug fixes
Expand Down
20 changes: 20 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,26 @@ Install headless-gl dependencies https://github.com/stackgl/headless-gl#windows
copy node_modules/headless-gl/deps/windows/dll/x64/*.dll c:\windows\system32
```

### Docker

#### Build the basic docker image

```shell
docker compose up --build build
```

#### Start development mode

```shell
docker compose up dev
```

#### Run tests

```shell
docker compose up test
```

## Creating a Standalone Build

A standalone build allows you to turn the contents of this repository into `maplibre-gl.js` and `maplibre-gl.css` files that can be included on an html page.
Expand Down
33 changes: 33 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
services:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does a docker-compose really make sense with only one service?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would reccomnd to add an entrypoint to the docker file by using npm run start and export 9966 port.
Also add some explanation to the CONTRIBUTING.md file on how to use this image.

Copy link
Author

Choose a reason for hiding this comment

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

Does a docker-compose really make sense with only one service?

I already imagine at least 1 or 2 other services (so I start by a first):

  • a headless web browser for testing purposes
  • a web server to mak run a release with some examples

Copy link
Collaborator

Choose a reason for hiding this comment

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

I still don't see a huge value here...
You can simply mount the entire cloned repo instead of a selective number of folders.
You can switch the entry point command to run different scripts from the package.json file.
Bottom line, this can be dramatically simplified.

build:
platform: linux/amd64
build:
platforms:
- "linux/amd64"
context: .
dockerfile: ./.devcontainer/Dockerfile
image: ghcr.io/maplibre/maplibre-gl-js:dev
volumes:
- ./:/maplibre-gl-js/

dev:
platform: linux/amd64
image: ghcr.io/maplibre/maplibre-gl-js:dev
working_dir: /maplibre-gl-js
volumes:
- ./:/maplibre-gl-js/
ports:
- 9966:9966
command: npm run start

test:
platform: linux/amd64
image: ghcr.io/maplibre/maplibre-gl-js:dev
volumes:
- ./:/maplibre-gl-js/
command:
- /bin/bash
- -c
- |
set -xe
npm run test