Skip to content

Commit

Permalink
chore: add docker file and dev guide
Browse files Browse the repository at this point in the history
Fixes #293
  • Loading branch information
oscarlorentzon committed Jan 19, 2021
1 parent d34b1f1 commit 3a849c1
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 21 deletions.
19 changes: 18 additions & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Facebook has adopted the [Contributor Covenant](https://www.contributor-covenant

## Contribution Prerequisites
- You have [Node](https://nodejs.org) installed at v10.0.0+ and [Yarn](https://classic.yarnpkg.com) at v1.2.0+.
- You are familiar with Git.
- You are familiar with [Git](https://git-scm.com/).

## Sending a Pull Request
We will review your pull request and either merge it, request changes to it, or close it with an explanation. We’ll do our best to provide updates and feedback throughout the process.
Expand All @@ -25,6 +25,23 @@ In order to accept your pull request, we need you to submit a CLA. You only need

[Complete your CLA here.](https://code.facebook.com/cla)

## Develop with Docker
1. Install [Docker](https://www.docker.com/).
2. Clone the repository.
3. Build the mapillary-js image:

```zsh
docker build -t mapillary-js .
```

4. Create a mapillary-js container and run it interactively:

```zsh
docker run -v "$(pwd)":/source/mapillary-js -p 8000:8000 --name mapillary-js-container -it mapillary-js

```

5. [Stop](https://docs.docker.com/engine/reference/commandline/stop/), [start](https://docs.docker.com/engine/reference/commandline/start/), and [attach](https://docs.docker.com/engine/reference/commandline/exec/) to the container.

## Development Workflow
After cloning MapillaryJS, run `yarn` to fetch its dependencies. Then, you can run several commands:
Expand Down
16 changes: 12 additions & 4 deletions .github/workflows/yarn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: '12.x'
node-version: '14.x'

- name: Install dependencies
run: yarn --frozen-lockfile
Expand All @@ -25,4 +23,14 @@ jobs:
run: yarn test

- name: Build documentation
run: yarn run build-docs
run: yarn build-docs
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: image
run: docker build . --file Dockerfile -t mapillary/mapillary-js:GITHUB_SHA

- name: Build
run: docker run mapillary/mapillary-js:$GITHUB_SHA /bin/sh -c "cd ../original-source/mapillary-js && yarn --frozen-lockfile $$ yarn test && yarn build-docs"
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM ubuntu:20.10

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
apt-get install -y \
git \
curl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
apt-get install -y nodejs

RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg \
| apt-key add && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" \
| tee /etc/apt/sources.list.d/yarn.list && \
apt update && \
apt install yarn

COPY . /source/original-source/mapillary-js

WORKDIR /source/mapillary-js
34 changes: 18 additions & 16 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
'use strict';

var autoprefixer = require('autoprefixer');
var express = require('express');
var brfs = require('brfs');
var browserify = require('browserify-middleware');
var fs = require('fs')
var path = require('path');
var postcss = require('postcss-middleware');
var tsify = require('tsify');
var inline = require('postcss-inline-svg')({
const autoprefixer = require('autoprefixer');
const express = require('express');
const brfs = require('brfs');
const browserify = require('browserify-middleware');
const fs = require('fs')
const path = require('path');
const postcss = require('postcss-middleware');
const tsify = require('tsify');
const inline = require('postcss-inline-svg')({
paths: ['./styles'],
encode: svg => Buffer.from(svg).toString('base64'),
transform: encoded => `"data:image/svg+xml;base64,${encoded}"`
});
var cssnano = require('cssnano')({
const cssnano = require('cssnano')({
preset: ['default', {
normalizeWhitespace: false,
svgo: {
Expand All @@ -26,7 +26,7 @@ var cssnano = require('cssnano')({
}],
});

var app = express();
const app = express();

app.get('/dist/mapillary.js', browserify('./src/Mapillary.ts', {
cache: 'dynamic',
Expand All @@ -41,19 +41,21 @@ app.get('/dist/mapillary.js', browserify('./src/Mapillary.ts', {
}));

app.get('/dist/mapillary.min.css', postcss({
src: () => { return path.join(__dirname, 'styles', '*.css'); },
plugins: [
src: () => { return path.join(__dirname, 'styles', '*.css'); },
plugins: [
autoprefixer,
inline,
cssnano,
]
}));

app.get('/debug', (_, res) => { res.redirect('/'); });

app.use(express.static(path.join(__dirname, 'debug')));
app.use('/dist', express.static(path.join(__dirname, 'dist')));

app.listen(3000, () => {
console.log('mapillary-js debug server running at http://localhost:3000');
const port = 8000;
app.listen(port, () => {
const message =
`mapillary-js debug server running at http://localhost:${port}`;
console.log(message);
});

0 comments on commit 3a849c1

Please sign in to comment.