Skip to content
Snippets Groups Projects
Commit 9abc3aaa authored by Thomas Buckley-Houston's avatar Thomas Buckley-Houston
Browse files

Refactor build process to not use pre-built bins

This means that there's now a canonical script that allows other
distributers to build Browsh. The only caveat being that the web
extension cannot be built (Mozilla only allows one signed `.xpi` per
version), so it is downloaded.
parent d6afc206
No related branches found
No related tags found
No related merge requests found
......@@ -11,3 +11,4 @@ webextension.go
webext/node_modules
webext/dist/*
dist
*.xpi
FROM bitnami/minideb:stretch as build
RUN install_packages \
curl \
ca-certificates \
git \
autoconf \
automake \
g++ \
protobuf-compiler \
zlib1g-dev \
libncurses5-dev \
libssl-dev \
pkg-config \
libprotobuf-dev \
make
# Install Golang
ENV GOROOT=/go
ENV GOPATH=/go-home
ENV PATH=$GOROOT/bin:$GOPATH/bin:$PATH
RUN curl -L -o go.tar.gz https://dl.google.com/go/go1.9.2.linux-amd64.tar.gz
RUN mkdir -p $GOPATH/bin
RUN tar -C / -xzf go.tar.gz
ENV BASE=$GOPATH/src/browsh/interfacer
WORKDIR $BASE
ADD interfacer $BASE
# Install `dep` the current defacto dependency manager for Golang
RUN $BASE/contrib/setup_dep.sh
# Install the tool to convert the web extenstion file into a Go-compatible binary
RUN go get -u gopkg.in/shuLhan/go-bindata.v3/...
# Build Browsh
RUN dep ensure
RUN $BASE/contrib/build_browsh.sh
###########################
# Actual final Docker image
###########################
FROM bitnami/minideb:stretch
RUN install_packages xvfb libgtk-3-0 curl ca-certificates bzip2 libdbus-glib-1-2 procps
ENV HOME=/app
WORKDIR /app
COPY --from=build /go-home/src/browsh/interfacer/browsh /app/browsh
RUN install_packages \
xvfb \
libgtk-3-0 \
curl \
ca-certificates \
bzip2 \
libdbus-glib-1-2 \
procps
# Block ads, etc. This includes porn just because this image is also used on the
# public SSH demo: `ssh brow.sh`.
RUN curl -o /etc/hosts https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn-social/hosts
# Don't use root
RUN useradd -m user --home /app
RUN chown user:user /app
USER user
ENV HOME=/app
WORKDIR /app
# These are needed to detect versions
ADD .travis.yml .
ADD ./webext/manifest.json .
# Setup Firefox
ENV PATH="/app/bin/firefox:${PATH}"
ADD ./interfacer/contrib/setup_firefox.sh .
ENV PATH="${HOME}/bin/firefox:${PATH}"
ADD .travis.yml .
ADD interfacer/contrib/setup_firefox.sh .
RUN ./setup_firefox.sh
RUN rm ./setup_firefox.sh && rm .travis.yml
# Setup Browsh
ADD ./interfacer/contrib/setup_browsh.sh .
ADD ./interfacer/src/browsh/version.go .
RUN VERSION_FILE=version.go ./setup_browsh.sh
RUN rm ./setup_browsh.sh && rm version.go
RUN rm setup_firefox.sh && rm .travis.yml
# Firefox behaves quite differently to normal on its first run, so by getting
# that over and done with here when there's no user to be dissapointed means
# that all future runs will be consistent.
RUN TERM=xterm script \
--return \
-c "/app/browsh" \
/dev/null \
>/dev/null & \
sleep 10
--return \
-c "/app/browsh" \
/dev/null \
>/dev/null & \
sleep 10
CMD ["/app/browsh"]
......@@ -59,7 +59,7 @@ package manager. The current Golang version being used is stored in `.travis.yml
You'll then need to install the project dependencies. For the webextension, just
run: `npm install` inside the `webext/` folder. For the CLI client you will first
need to install `dep`, there is a script for this in `interfacer/contrib/setup_go.sh`.
need to install `dep`, there is a script for this in `interfacer/contrib/setup_dep.sh`.
I don't fully understand Golang's best practices, but it seems you are forced to
keep your Go project's code under `$GOPATH/src`, you might be able to get away
with symlinks. Anyway, to install the dependencies use: `dep ensure` inside the
......@@ -74,6 +74,13 @@ Then the ideal setup for development is:
webextension everytime webpack rebuilds it: (in `webext/dist`)
`web-ext run --verbose`
## Building a Browsh release
If you'd like to build Browsh for a new package manager, or for any other reason,
you can use the script at `interfacer/contrib/build_browsh.go` as a guide. Note
you won't be able to build the web extension as Mozilla only allows one canonical
version of web extensions per version number. So the build script downloads the
official web extension `.xpi` file from the Mozilla archives.
## Tests
For the webextension: in `webext/` folder, `npm test`
......
......@@ -4,7 +4,7 @@ set -e
PROJECT_ROOT=$(git rev-parse --show-toplevel)
browsh_version=$($PROJECT_ROOT/contrib/get_browsh_version.sh)
browsh_version=$($PROJECT_ROOT/interfacer/contrib/get_browsh_version.sh)
latest_tagged_version=$(git tag --sort=v:refname --list 'v*.*.*' | tail -n1 | sed -e "s/^v//")
echo "Browsh version: $browsh_version"
......
#!/bin/bash
# This is for building a production version of Browsh.
# To build Browsh during development see:
# https://github.com/browsh-org/browsh#contributing
# This script depends on Golang and go-bindata
# `go get -u gopkg.in/shuLhan/go-bindata.v3/...`
set -e
INTERFACER_ROOT=$(readlink -m "$( cd "$(dirname "$0")" ; pwd -P )"/../)
version_file=$INTERFACER_ROOT/src/browsh/version.go
line=$(cat $version_file | grep 'browshVersion')
version=$(echo $line | grep -o '".*"' | sed 's/"//g')
base='https://github.com/browsh-org/browsh/releases/download'
release_url="$base/v$version/browsh-${version}-an.fx.xpi"
xpi_file=$INTERFACER_ROOT/browsh.xpi
destination=$INTERFACER_ROOT/src/browsh/webextension.go
curl -L -o $xpi_file $release_url
XPI_FILE=$xpi_file BIN_FILE=$destination \
$INTERFACER_ROOT/contrib/xpi2bin.sh
cd $INTERFACER_ROOT
go build -o browsh src/main.go
#!/bin/bash
# I suspect this will be mostly used by automated CI.
# For example; in creating the Browsh Docker image. We don't actually build
# Browsh in the Dockerfile because that would require signing the webextension
# again, which can't be done as only one canonical release of a webextension is
# allowed by MDN per semantic version. It's actually quite good to not have to
# repeat the build process (having done so in Travis after successfully
# passing tests). So we simply just download the already built binary.
set -e
# This will typically be run inside Docker where we don't have the original
# source code.
line=$(cat $VERSION_FILE | grep 'browshVersion')
version=$(echo $line | grep -o '".*"' | sed 's/"//g')
base='https://github.com/browsh-org/browsh/releases/download'
release_url="$base/v$version/browsh_${version}_linux_amd64"
curl -L -o browsh $release_url
chmod a+x browsh
File moved
#!/bin/bash
set -e
INTERFACER_ROOT=$(readlink -m "$( cd "$(dirname "$0")" ; pwd -P )"/../)
go-bindata -version
go-bindata \
-nocompress \
-prefix $INTERFACER_ROOT \
-pkg browsh \
-o $BIN_FILE \
$XPI_FILE
ls -alh $INTERFACER_ROOT/src/browsh/webextension.go
echo "go-bindata exited with $(echo $?)"
......@@ -220,7 +220,7 @@ func firefoxMarionette() {
// Install the Browsh extension that was bundled with `go-bindata` under
// `webextension.go`.
func installWebextension() {
data, err := Asset("/webext/dist/web-ext-artifacts/browsh.xpi")
data, err := Asset("/browsh.xpi")
if err != nil {
Shutdown(err)
}
......
package browsh
var browshVersion = "1.4.8"
var browshVersion = "1.4.9"
......@@ -22,7 +22,7 @@ ls -alh .
$NODE_BIN/web-ext build --overwrite-dest
ls -alh web-ext-artifacts
version=$($PROJECT_ROOT/contrib/get_browsh_version.sh)
version=$($PROJECT_ROOT/interfacer/contrib/get_browsh_version.sh)
xpi_file=browsh-$version-an+fx.xpi
zip_file=browsh-$version.zip
......@@ -51,13 +51,5 @@ cp -f $source_file $bundle_file
echo "Bundling $source_file to $destination using internal path $bundle_file"
go-bindata -version
go-bindata \
-nocompress \
-prefix $PROJECT_ROOT \
-pkg browsh \
-o $destination \
$bundle_file
ls -alh $PROJECT_ROOT/interfacer/src/browsh/webextension.go
echo "go-bindata exited with $(echo $?)"
XPI_FILE=$bundle_file BIN_FILE=$destination \
$PROJECT_ROOT/interfacer/contrib/xpi2bin.sh
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment