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

[T-242] Docker for alpine and centos binaries #24

Merged
merged 55 commits into from
Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
edc44a2
experiment with building using docker
DeMoorJasper Dec 13, 2019
4e5ebd8
fix command
DeMoorJasper Dec 13, 2019
a60d5e8
remove experimentation
DeMoorJasper Dec 13, 2019
b7a5505
run docker builds on mac and linux
DeMoorJasper Dec 13, 2019
22b6166
musl fi
DeMoorJasper Dec 13, 2019
e07fdd1
new backend
DeMoorJasper Dec 14, 2019
13503c7
cleanup code a lil
DeMoorJasper Dec 14, 2019
f58684c
minor cleanup
DeMoorJasper Dec 14, 2019
db70ffd
cleanup comments
DeMoorJasper Dec 14, 2019
aff7678
remove comment about file amount diff as it randomly dissapeared
DeMoorJasper Dec 14, 2019
cf037a5
performance tweaks
DeMoorJasper Dec 14, 2019
8044c7d
performance test
DeMoorJasper Dec 14, 2019
2ef02e9
revert some changes
DeMoorJasper Dec 15, 2019
6d59c33
update
DeMoorJasper Dec 15, 2019
fcba5cd
fix bugs
DeMoorJasper Dec 15, 2019
8863fab
update
DeMoorJasper Dec 15, 2019
35a97c5
cleanup and make stable across osses
DeMoorJasper Dec 15, 2019
92ff573
use fts on mac, legacy on linux
DeMoorJasper Dec 15, 2019
3988d24
Delete snapshot.txt
DeMoorJasper Dec 15, 2019
6246e67
dont build docker images on os x
DeMoorJasper Dec 15, 2019
27caed6
performance enhancements
DeMoorJasper Dec 16, 2019
6f02559
fix warning on linux
DeMoorJasper Dec 16, 2019
6bda56f
tweak fts to prevent warning
DeMoorJasper Dec 16, 2019
53bd896
add prebuild as a test
DeMoorJasper Dec 16, 2019
aa6ec19
docker builds should probably be seperate and complex in azure pipeli…
DeMoorJasper Dec 16, 2019
db1cb20
update def __throw
DeMoorJasper Dec 16, 2019
5fb1ac8
undo using openat, it's not that much faster and adds complexity
DeMoorJasper Dec 16, 2019
1130453
Revert "undo using openat, it's not that much faster and adds complex…
DeMoorJasper Dec 17, 2019
1d67ae2
fix docker build script
DeMoorJasper Dec 17, 2019
17d46b8
maybe this works?
DeMoorJasper Feb 9, 2020
952c34a
fix pipeline name?
DeMoorJasper Feb 9, 2020
8e9d363
update windows binaries watchman
DeMoorJasper Feb 9, 2020
d6014e3
use latest windows agent
DeMoorJasper Feb 9, 2020
4f4383e
use container from azure-pipelines.tml
DeMoorJasper Feb 9, 2020
b49d7fd
update images used by pipelines
DeMoorJasper Feb 9, 2020
2582a54
remove docker agent script
DeMoorJasper Feb 9, 2020
486840d
azure pipelines might work now? Plz?
DeMoorJasper Feb 9, 2020
9cb8776
add bash to alpine image
DeMoorJasper Feb 9, 2020
e75fd08
.
DeMoorJasper Feb 9, 2020
60af391
azure be green
DeMoorJasper Feb 9, 2020
7713307
build against node 10 & 12 not 8 and 10
DeMoorJasper Feb 9, 2020
f2fa2ab
rename alpine_linux => alpine
DeMoorJasper Feb 9, 2020
ebf80c5
drop watchman support for windows as its in alpha
DeMoorJasper Feb 9, 2020
4076065
get tests to pass for now...
DeMoorJasper Feb 9, 2020
4f9d6b4
tweak legacy and remove watchman in windows
DeMoorJasper Feb 9, 2020
fb3bfcc
damn that was so easy, how did I miss it for so long...
DeMoorJasper Feb 9, 2020
75f63ba
woops accidentally removed a line of code
DeMoorJasper Feb 9, 2020
fe16003
cleanup pt1
DeMoorJasper Feb 9, 2020
522b966
cleanup makefile
DeMoorJasper Feb 9, 2020
d3463e7
just add the watchman bin to git
DeMoorJasper Feb 9, 2020
9f2fb90
update pipeline to use watchman from repo
DeMoorJasper Feb 9, 2020
95ddfcd
fix windows?
DeMoorJasper Feb 9, 2020
5360e89
fix?
DeMoorJasper Feb 9, 2020
d5585bb
just fix file structure it'll be easier...
DeMoorJasper Feb 9, 2020
ab25cd1
revert back to old windows, hopefully they dont deprecate it any time…
DeMoorJasper Feb 9, 2020
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ build/
prebuilds/
node_modules/
token.txt
.DS_Store
.idea
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.PHONY: build run

current_dir = $(shell pwd)

docker-build:
docker build -t jasperdm/centos-watchman -f ./docker-agents/centos.Dockerfile .
docker build -t jasperdm/alpine-watchman -f ./docker-agents/alpine.Dockerfile .

27 changes: 9 additions & 18 deletions azure-pipelines-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ jobs:
- job: ${{ parameters.name }}
pool:
vmImage: ${{ parameters.vmImage }}
${{ if eq(parameters.name, 'Linux') }}:
container: jotadrilo/watchman:latest
${{ if or(eq(parameters.name, 'Alpine'), eq(parameters.name, 'CentOS7')) }}:
container: ${{ parameters.container }}
strategy:
matrix:
node_8_x:
node_version: 8.x
publish_artifacts: false
node_10_x:
node_version: 10.x
publish_artifacts: false
node_12_x:
node_version: 12.x
publish_artifacts: true
maxParallel: 3
steps:
- task: NodeTool@0
inputs:
Expand All @@ -28,14 +27,8 @@ jobs:

- ${{ if eq(parameters.name, 'Windows') }}:
- script: |
curl -sSf -L -o watchman.zip https://github.com/facebook/watchman/suites/296618337/artifacts/249606
displayName: Download Watchman
- task: ExtractFiles@1
inputs:
archiveFilePatterns: 'watchman.zip'
destinationFolder: $(Agent.HomeDirectory)
cleanDestinationFolder: false
displayName: Extract Watchman
cp -rf $(System.DefaultWorkingDirectory)\watchman $(Agent.HomeDirectory)
displayName: Copy Watchman
- script: |
set PATH=%PATH%;$(Agent.HomeDirectory)\watchman\windows\bin
echo "##vso[task.setvariable variable=PATH]%PATH%"
Expand All @@ -46,12 +39,10 @@ jobs:
displayName: Install dependencies
- script: npm test
displayName: Run tests
- script: npm run prebuild
displayName: Test prebuild

- ${{ if startsWith(variables['Build.SourceBranch'], 'refs/tags/v') }}:
- script: npm run prebuild
displayName: Prebuild
condition: and(succeeded(), eq(variables['publish_artifacts'], 'true'))

- task: PublishBuildArtifacts@1
displayName: Publish Artifacts
condition: and(succeeded(), eq(variables['publish_artifacts'], 'true'))
Expand Down
9 changes: 8 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ jobs:

- template: azure-pipelines-template.yml
parameters:
name: Linux
name: Alpine
vmImage: ubuntu-16.04
container: jasperdm/alpine-watchman:latest

- template: azure-pipelines-template.yml
parameters:
name: CentOS7
vmImage: ubuntu-16.04
container: jasperdm/centos-watchman:latest

- template: azure-pipelines-template.yml
parameters:
Expand Down
2 changes: 1 addition & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"src/watchman/WatchmanBackend.cc",
"src/shared/BruteForceBackend.cc",
"src/linux/InotifyBackend.cc",
"src/unix/fts.cc"
"src/unix/legacy.cc"
DeMoorJasper marked this conversation as resolved.
Show resolved Hide resolved
],
"defines": [
"WATCHMAN",
Expand Down
53 changes: 53 additions & 0 deletions docker-agents/alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
FROM node:12-alpine

RUN apk update
RUN apk upgrade

# Azure Pipelines stuff
RUN apk add --no-cache --virtual .pipeline-deps readline linux-pam \
&& apk add bash sudo shadow \
&& apk del .pipeline-deps

RUN apk add --no-cache \
libcrypto1.1 \
libgcc \
libstdc++ \
ca-certificates \
openssl \
automake \
autoconf \
bash \
build-base \
libtool \
linux-headers \
openssl-dev \
python-dev \
g++ \
gcc \
git \
fts-dev \
python

ENV WATCHMAN_VERSION=4.9.0 \
WATCHMAN_SHA256=1f6402dc70b1d056fffc3748f2fdcecff730d8843bb6936de395b3443ce05322

RUN cd /tmp \
&& wget -O watchman.tar.gz "https://github.com/facebook/watchman/archive/v${WATCHMAN_VERSION}.tar.gz" \
&& echo "$WATCHMAN_SHA256 *watchman.tar.gz" | sha256sum -c - \
&& tar -xz -f watchman.tar.gz -C /tmp/ \
&& rm -rf watchman.tar.gz

RUN cd /tmp/watchman-${WATCHMAN_VERSION} \
&& ./autogen.sh \
&& ./configure --enable-lenient \
&& make \
&& make install \
&& cd $HOME \
&& rm -rf /tmp/*

RUN watchman --version
RUN command -v bash

# Set Node runtime as it's using musl
LABEL "com.azure.dev.pipelines.agent.handler.node.path"="/usr/local/bin/node"
CMD [ "node" ]
37 changes: 37 additions & 0 deletions docker-agents/centos.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM centos/devtoolset-7-toolchain-centos7

USER 0

ENV WATCHMAN_VERSION=4.9.0 \
WATCHMAN_SHA256=1f6402dc70b1d056fffc3748f2fdcecff730d8843bb6936de395b3443ce05322

RUN yum install -y \
wget \
libgcc \
libstdc++ \
ca-certificates \
openssl \
automake \
autoconf \
bash \
libtool \
openssl-devel \
python-devel \
gcc \
git

RUN cd /tmp \
&& wget -O watchman.tar.gz "https://github.com/facebook/watchman/archive/v${WATCHMAN_VERSION}.tar.gz" \
&& echo "$WATCHMAN_SHA256 *watchman.tar.gz" | sha256sum -c - \
&& tar -xz -f watchman.tar.gz -C /tmp/ \
&& rm -rf watchman.tar.gz

RUN cd /tmp/watchman-${WATCHMAN_VERSION} \
&& ./autogen.sh \
&& ./configure \
&& make \
&& make install \
&& cd $HOME \
&& rm -rf /tmp/*

RUN watchman --version
8 changes: 7 additions & 1 deletion src/unix/fts.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#include <string>
#define __THROW // weird error on linux

// weird error on linux
#ifdef __THROW
#undef __THROW
DeMoorJasper marked this conversation as resolved.
Show resolved Hide resolved
#endif
#define __THROW

#include <fts.h>
#include "../DirTree.hh"
#include "../shared/BruteForceBackend.hh"
Expand Down
67 changes: 67 additions & 0 deletions src/unix/legacy.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <string>

// weird error on linux
#ifdef __THROW
#undef __THROW
#endif
#define __THROW

#ifdef _LIBC
# include <include/sys/stat.h>
#else
# include <sys/stat.h>
#endif
#include <dirent.h>
#include <unistd.h>

#include "../DirTree.hh"
#include "../shared/BruteForceBackend.hh"

#define CONVERT_TIME(ts) ((uint64_t)ts.tv_sec * 1000000000 + ts.tv_nsec)
#if __APPLE__
#define st_mtim st_mtimespec
#endif
#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))

void iterateDir(Watcher &watcher, const std::shared_ptr <DirTree> tree, const char *relative, int parent_fd, const std::string dirname) {
int open_flags = (O_RDONLY | O_CLOEXEC | O_DIRECTORY | O_NOCTTY | O_NONBLOCK | O_NOFOLLOW);
int new_fd = openat(parent_fd, relative, open_flags);

struct stat rootAttributes;
fstatat(new_fd, ".", &rootAttributes, AT_SYMLINK_NOFOLLOW);
tree->add(dirname, CONVERT_TIME(rootAttributes.st_mtim), true);

if (DIR *dir = fdopendir(new_fd)) {
while (struct dirent *ent = (errno = 0, readdir(dir))) {
if (ISDOT(ent->d_name)) continue;

std::string fullPath = dirname + "/" + ent->d_name;

if (watcher.mIgnore.count(fullPath) == 0) {
struct stat attrib;
fstatat(new_fd, ent->d_name, &attrib, AT_SYMLINK_NOFOLLOW);
bool isDir = ent->d_type == DT_DIR;

if (isDir) {
iterateDir(watcher, tree, ent->d_name, new_fd, fullPath);
} else {
tree->add(fullPath, CONVERT_TIME(attrib.st_mtim), isDir);
}
}
}
}

close(new_fd);

if (errno) {
throw WatcherError(strerror(errno), &watcher);
}
}

void BruteForceBackend::readTree(Watcher &watcher, std::shared_ptr <DirTree> tree) {
int fd = open(watcher.mDir.c_str(), O_RDONLY);
if (fd) {
iterateDir(watcher, tree, ".", fd, watcher.mDir);
close(fd);
}
}
32 changes: 17 additions & 15 deletions test/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,22 +606,24 @@ describe('watcher', () => {
});
});

describe('watchman errors', () => {
it('should emit an error when watchman dies', async () => {
let dir = path.join(fs.realpathSync(require('os').tmpdir()), Math.random().toString(31).slice(2));
fs.mkdirpSync(dir);
await new Promise(resolve => setTimeout(resolve, 100));

let p = new Promise(resolve => {
watcher.subscribe(dir, (err, events) => {
setImmediate(() => resolve(err));
}, {backend: 'watchman'});
});
if (backends.includes('watchman')) {
describe('watchman errors', () => {
it('should emit an error when watchman dies', async () => {
let dir = path.join(fs.realpathSync(require('os').tmpdir()), Math.random().toString(31).slice(2));
fs.mkdirpSync(dir);
await new Promise(resolve => setTimeout(resolve, 100));

let p = new Promise(resolve => {
watcher.subscribe(dir, (err, events) => {
setImmediate(() => resolve(err));
}, {backend: 'watchman'});
});

execSync('watchman shutdown-server');
execSync('watchman shutdown-server');

let err = await p;
assert(err, 'No error was emitted');
let err = await p;
assert(err, 'No error was emitted');
});
});
});
}
});
Binary file added watchman/windows/bin/gflags.dll
Binary file not shown.
Binary file added watchman/windows/bin/glog.dll
Binary file not shown.
Binary file added watchman/windows/bin/watchman.exe
Binary file not shown.