Skip to content

Commit

Permalink
fix: update fpm to 1.6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Sep 30, 2016
1 parent 6735da5 commit 7a5252c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 88 deletions.
2 changes: 1 addition & 1 deletion docker/4/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM electronuserland/electron-builder:base

ENV NODE_VERSION 4.5.0
ENV NODE_VERSION 4.6.0

# https://github.com/npm/npm/issues/4531
RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \
Expand Down
2 changes: 1 addition & 1 deletion docker/6/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM electronuserland/electron-builder:base

ENV NODE_VERSION 6.6.0
ENV NODE_VERSION 6.7.0

# https://github.com/npm/npm/issues/4531
RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \
Expand Down
66 changes: 4 additions & 62 deletions docker/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ ENV XZ_VERSION 5.2.2
# we don't use our bundled 7za because it is better to build for specific platform - not generic
ENV USE_SYSTEM_7ZA true

# we don't use our bundled fpm because it is better to build ruby & tools for specific platform - not generic. And easy to maintain (update ruby and so on).
ENV USE_SYSTEM_FPM true

ENV DEBUG_COLORS true
ENV FORCE_COLOR true

Expand All @@ -23,7 +20,9 @@ RUN apt-get update -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
curl -L http://tukaani.org/xz/xz-$XZ_VERSION.tar.xz | tar -xJ && cd xz-$XZ_VERSION && ./configure && make && make install && cd .. && rm -rf xz-$XZ_VERSION && ldconfig && \
mkdir -p /tmp/7z && curl -L http://downloads.sourceforge.net/project/p7zip/p7zip/15.14.1/p7zip_15.14.1_src_all.tar.bz2 | tar -xj -C /tmp/7z --strip-components 1 && cd /tmp/7z && cp makefile.linux_amd64_asm makefile.machine && make && make install && rm -rf /tmp/7z
mkdir -p /tmp/7z && curl -L http://downloads.sourceforge.net/project/p7zip/p7zip/16.02/p7zip_16.02_src_all.tar.bz2 | tar -xj -C /tmp/7z --strip-components 1 && cd /tmp/7z && cp makefile.linux_amd64_asm makefile.machine && make && make install && rm -rf /tmp/7z

COPY test.sh /test.sh

# nodejs keys
RUN set -ex \
Expand All @@ -40,8 +39,6 @@ RUN set -ex \
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
done

COPY test.sh /test.sh

WORKDIR /project

# fix error /usr/local/bundle/gems/fpm-1.5.0/lib/fpm/package/freebsd.rb:72:in `encode': "\xE2" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError)
Expand All @@ -50,59 +47,4 @@ WORKDIR /project
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

# Ruby
# copied from https://github.com/docker-library/ruby/blob/0b94677b368947b64dcdcb312cd81ba946df3676/2.3/Dockerfile

# skip installing gem documentation
RUN mkdir -p /usr/local/etc \
&& { \
echo 'install: --no-document'; \
echo 'update: --no-document'; \
} >> /usr/local/etc/gemrc

ENV RUBY_MAJOR 2.3
ENV RUBY_VERSION 2.3.1
ENV RUBY_DOWNLOAD_SHA256 b87c738cb2032bf4920fef8e3864dc5cf8eae9d89d8d523ce0236945c5797dcd
ENV RUBYGEMS_VERSION 2.6.4
ENV BUNDLER_VERSION 1.12.4

# some of ruby's build scripts are written in ruby
# we purge this later to make sure our final image uses what we just built
RUN set -ex \
&& buildDeps=' \
bison \
libgdbm-dev \
ruby \
' \
&& apt-get update \
&& apt-get install -y --no-install-recommends $buildDeps \
&& rm -rf /var/lib/apt/lists/* \
&& curl -fSL -o ruby.tar.gz "http://cache.ruby-lang.org/pub/ruby/$RUBY_MAJOR/ruby-$RUBY_VERSION.tar.gz" \
&& echo "$RUBY_DOWNLOAD_SHA256 *ruby.tar.gz" | sha256sum -c - \
&& mkdir -p /usr/src/ruby \
&& tar -xzf ruby.tar.gz -C /usr/src/ruby --strip-components=1 \
&& rm ruby.tar.gz \
&& cd /usr/src/ruby \
&& { echo '#define ENABLE_PATH_CHECK 0'; echo; cat file.c; } > file.c.new && mv file.c.new file.c \
&& autoconf \
&& ./configure --disable-install-doc \
&& make -j"$(nproc)" \
&& make install \
&& apt-get purge -y --auto-remove $buildDeps \
&& gem update --system $RUBYGEMS_VERSION \
&& rm -r /usr/src/ruby \
&& cd / && gem install bundler --version "$BUNDLER_VERSION"

# install things globally, for great justice
# and don't create ".bundle" in all our apps
ENV GEM_HOME /usr/local/bundle
ENV BUNDLE_PATH="$GEM_HOME" \
BUNDLE_BIN="$GEM_HOME/bin" \
BUNDLE_SILENCE_ROOT_WARNING=1 \
BUNDLE_APP_CONFIG="$GEM_HOME"
ENV PATH $BUNDLE_BIN:$PATH
RUN mkdir -p "$GEM_HOME" "$BUNDLE_BIN" \
&& chmod 777 "$GEM_HOME" "$BUNDLE_BIN" \
&& mkdir -p /tmp/fpm && curl -L https://github.com/jordansissel/fpm/archive/103602c83215c0f7d18e32316268a3db38de5cc0.tar.gz | tar -xz -C /tmp/fpm --strip-components 1 && cd /tmp/fpm && bundle install && make install && cd .. && rm -rf /tmp/fpm
ENV LC_ALL en_US.UTF-8
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"lint": "tslint 'src/**/*.ts' 'test/src/**/*.ts' 'nsis-auto-updater/src/**/*.ts'",
"pretest": "npm run compile && npm run lint && npm run pack-updater",
"test": "node ./test/out/helpers/runTests.js",
"test-linux": "docker run --rm -ti -v ${PWD}:/project -v ${PWD##*/}-node-modules:/project/node_modules -v ~/.electron:/root/.electron electronuserland/electron-builder:wine /test.sh",
"pack-updater": "cd nsis-auto-updater && npm install --production --no-bin-links && npm prune --production && rm -rf nm && cp -a node_modules nm && cd ..",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"//": "Update wiki if docs changed. Update only if functionalily are generally available (latest release, not next)",
Expand Down Expand Up @@ -88,9 +89,9 @@
"progress": "^1.1.8",
"progress-stream": "^1.2.0",
"read-installed": "^4.0.3",
"sanitize-filename": "^1.6.0",
"sanitize-filename": "^1.6.1",
"semver": "^5.3.0",
"source-map-support": "^0.4.2",
"source-map-support": "^0.4.3",
"tunnel-agent": "^0.4.3",
"update-notifier": "^1.0.2",
"uuid-1345": "^0.99.6",
Expand All @@ -116,8 +117,8 @@
"@types/source-map-support": "^0.2.28",
"ava-tf": "^0.16.0",
"babel-plugin-array-includes": "^2.0.3",
"babel-plugin-transform-es2015-destructuring": "^6.9.0",
"babel-plugin-transform-es2015-parameters": "^6.11.4",
"babel-plugin-transform-es2015-destructuring": "^6.16.0",
"babel-plugin-transform-es2015-parameters": "^6.16.0",
"babel-plugin-transform-es2015-spread": "^6.8.0",
"decompress-zip": "^0.3.0",
"diff": "^3.0.0",
Expand Down
16 changes: 13 additions & 3 deletions src/targets/fpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { LinuxBuildOptions, Arch } from "../metadata"
import { smarten, PlatformPackager, TargetEx } from "../platformPackager"
import { use, exec } from "../util/util"
import * as path from "path"
import { downloadFpm } from "../util/binDownload"
import { getBin } from "../util/binDownload"
import { readFile, outputFile } from "fs-extra-p"
import { Promise as BluebirdPromise } from "bluebird"
import { LinuxTargetHelper, installPrefix } from "./LinuxTargetHelper"
Expand All @@ -15,8 +15,18 @@ const template = require("lodash.template")
const __awaiter = require("../util/awaiter")

const fpmPath = (process.platform === "win32" || process.env.USE_SYSTEM_FPM === "true") ?
BluebirdPromise.resolve("fpm") :
downloadFpm(process.platform === "darwin" ? "1.5.1-20150715-2.2.2" : "1.5.0-2.3.1", process.platform === "darwin" ? "osx" : `linux-x86${process.arch === "ia32" ? "" : "_64"}`)
BluebirdPromise.resolve("fpm") : downloadFpm()

// can be called in parallel, all calls for the same version will get the same promise - will be downloaded only once
function downloadFpm(): Promise<string> {
const version = process.platform === "darwin" ? "fpm-1.6.3-20150715-2.2.2" : "fpm-1.6.3-2.3.1"
const osAndArch = process.platform === "darwin" ? "mac" : `linux-x86${process.arch === "ia32" ? "" : "_64"}`
const sha2 = process.platform === "darwin" ? "1b13080ecfd2b6fddb984ed6e1dfcb38cdf5b051a04d609c2a95227ed9a5ecbc" :
(process.arch === "ia32" ? "b55f25749a27097140171f073466c52e59f733a275fea99e2334c540627ffc62" : "4c6fc529e996f7ff850da2d0bb6c85080e43be672494b14c0c6bdcc03bf57328")

return getBin("fpm", version, `https://dl.bintray.com/electron-userland/bin/${version}-${osAndArch}.7z`, sha2)
.then(it => path.join(it, "fpm"))
}

export default class FpmTarget extends TargetEx {
private readonly options = Object.assign({}, this.packager.platformSpecificBuildOptions, (<any>this.packager.devMetadata.build)[this.name])
Expand Down
22 changes: 5 additions & 17 deletions src/util/binDownload.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { statOrNull, spawn, debug, debug7zArgs, getTempName } from "./util"
import { rename, remove, unlink, emptyDir } from "fs-extra-p"
import { rename, unlink, emptyDir } from "fs-extra-p"
import { download } from "./httpRequest"
import { path7za } from "7zip-bin"
import * as path from "path"
Expand All @@ -11,18 +11,12 @@ const __awaiter = require("./awaiter")

const versionToPromise = new Map<string, BluebirdPromise<string>>()

// can be called in parallel, all calls for the same version will get the same promise - will be downloaded only once
export function downloadFpm(version: string, osAndArch: string): Promise<string> {
return getBin("fpm", `fpm-${version}-${osAndArch}`, `https://github.com/develar/fpm-self-contained/releases/download/v${version}/${`fpm-${version}-${osAndArch}`}.7z`)
.then(it => path.join(it, "fpm"))
}

export function getBinFromBintray(name: string, version: string, sha2?: string): Promise<string> {
export function getBinFromBintray(name: string, version: string, sha2: string): Promise<string> {
const dirName = `${name}-${version}`
return getBin(name, dirName, `https://dl.bintray.com/electron-userland/bin/${dirName}.7z`, sha2)
}

export function getBin(name: string, dirName: string, url: string, sha2?: string): Promise<string> {
export function getBin(name: string, dirName: string, url: string, sha2: string): Promise<string> {
let promise = versionToPromise.get(dirName)
// if rejected, we will try to download again
if (promise != null && !promise.isRejected()) {
Expand All @@ -38,7 +32,7 @@ export function getBin(name: string, dirName: string, url: string, sha2?: string
// * don't need to find node_modules
// * don't pollute user project dir (important in case of 1-package.json project structure)
// * simplify/speed-up tests (don't download fpm for each test project)
async function doGetBin(name: string, dirName: string, url: string, sha2?: string): Promise<string> {
async function doGetBin(name: string, dirName: string, url: string, sha2: string): Promise<string> {
const cachePath = path.join(homedir(), ".cache", name)
const dirPath = path.join(cachePath, dirName)

Expand All @@ -63,20 +57,14 @@ async function doGetBin(name: string, dirName: string, url: string, sha2?: strin
cwd: cachePath,
})

const isOldMethod = sha2 == null

await BluebirdPromise.all([
rename(isOldMethod ? path.join(tempUnpackDir, dirName) : tempUnpackDir, dirPath)
rename(tempUnpackDir, dirPath)
.catch(e => {
console.warn(`Cannot move downloaded ${name} into final location (another process downloaded faster?): ${e}`)
}),
unlink(archiveName),
])

if (isOldMethod) {
await remove(tempUnpackDir)
}

debug(`${name}} downloaded to ${dirPath}`)
return dirPath
}

0 comments on commit 7a5252c

Please sign in to comment.