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

For windows #101

Open
wants to merge 15 commits into
base: master
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
94 changes: 94 additions & 0 deletions Dockerfile.windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
ARG OS_RELEASE

FROM mcr.microsoft.com/windows/servercore:${OS_RELEASE} as download

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

ENV GPG_VERSION 2.3.4

RUN Invoke-WebRequest $('https://files.gpg4win.org/gpg4win-vanilla-{0}.exe' -f $env:GPG_VERSION) -OutFile 'gpg4win.exe' -UseBasicParsing ; \
Start-Process .\gpg4win.exe -ArgumentList '/S' -NoNewWindow -Wait

RUN @( \
'4ED778F539E3634C779C87C6D7062848A1AB005C', \
'94AE36675C464D64BAFA68DD7434390BDBE9B9C5', \
'74F12602B6F1C4E913FAA37AD3A89613643B6201', \
'71DCFD284A79C3B38668286BC97EC7A07EDE3FC1', \
'8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600', \
'C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8', \
'C82FA3AE1CBEDC6BE46B9360C43CEC45C17AB93C', \
'DD8F2338BAE7501E3DD5AC78C273792F7D83545D', \
'A48C2BEE680E841632CD4E44F07496B3EB3C1762', \
'108F52B48DB57BB0CC439B2997B01419BD92F80A', \
'B9E2F5981AA6E0CD28160D9FF13993A75599653C', \
'9554F04D7259F04124DE6B476D5A82AC7E37093B', \
'1C050899334244A8AF75E53792EF661D867B9DFA', \
'B9AE9905FFD7803F25714661B63B535A4C206CA9' \
) | foreach { \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys $_ ; \
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys $_ ; \
}

ENV NODE_VERSION 11.10.0

RUN Invoke-WebRequest $('https://nodejs.org/dist/v{0}/SHASUMS256.txt.asc' -f $env:NODE_VERSION) -OutFile 'SHASUMS256.txt.asc' -UseBasicParsing ; \
gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc

RUN Invoke-WebRequest $('https://nodejs.org/dist/v{0}/node-v{0}-win-x64.zip' -f $env:NODE_VERSION) -OutFile 'node.zip' -UseBasicParsing ; \
$sum = $(cat SHASUMS256.txt.asc | sls $(' node-v{0}-win-x64.zip' -f $env:NODE_VERSION)) -Split ' ' ; \
if ((Get-FileHash node.zip -Algorithm sha256).Hash -ne $sum[0]) { Write-Error 'SHA256 mismatch' } ; \
Expand-Archive node.zip -DestinationPath C:\ ; \
Rename-Item -Path $('C:\node-v{0}-win-x64' -f $env:NODE_VERSION) -NewName 'C:\nodejs'

ENV YARN_VERSION 0.24.6

RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; \
Invoke-WebRequest $('https://yarnpkg.com/downloads/{0}/yarn-{0}.msi' -f $env:YARN_VERSION) -OutFile yarn.msi -UseBasicParsing ; \
$sig = Get-AuthenticodeSignature yarn.msi ; \
if ($sig.Status -ne 'Valid') { Write-Error 'Authenticode signature is not valid' } ; \
Write-Output $sig.SignerCertificate.Thumbprint ; \
if (@( \
'7E253367F8A102A91D04829E37F3410F14B68A5F', \
'AF764E1EA56C762617BDC757C8B0F3780A0CF5F9' \
) -notcontains $sig.SignerCertificate.Thumbprint) { Write-Error 'Unknown signer certificate' } ; \
Start-Process msiexec.exe -ArgumentList '/i', 'yarn.msi', '/quiet', '/norestart' -NoNewWindow -Wait

FROM download as build

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

ENV NPM_CONFIG_LOGLEVEL info

COPY --from=download /nodejs /nodejs
COPY --from=download [ "/Program Files (x86)/yarn", "/yarn" ]

RUN $env:PATH = 'C:\nodejs;C:\yarn\bin;{0}' -f $env:PATH ; \
[Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine)

CMD [ "node.exe" ]

FROM build

RUN Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
RUN choco install git -y

RUN $url = 'https://cygwin.com/setup-x86_64.exe'; \
Invoke-WebRequest -Uri $url -OutFile 'C:/setup-x86_64.exe'; \
New-Item -ItemType directory -Path 'C:/tmp'; \
Start-Process "C:/setup-x86_64.exe" -NoNewWindow -Wait -PassThru -ArgumentList @('-q','-v','-n','-B','-R','C:/cygwin64','-l','C:/tmp','-s','http://ctm.crouchingtigerhiddenfruitbat.org/pub/cygwin/circa/64bit/2019/03/06/161558','-X','-P', 'default'); \
Start-Process "C:/cygwin64/bin/cygcheck.exe" -NoNewWindow -Wait -PassThru -ArgumentList @('-c'); \
Remove-Item -Path 'C:/tmp' -Force -Recurse -ErrorAction Ignore;

WORKDIR C:/cf-container-logger

COPY package.json ./

COPY yarn.lock ./

RUN yarn install --frozen-lockfile --production

COPY . ./

LABEL owner="codefresh.io"

CMD ["powershell", "./lib/forever.ps1"]
10 changes: 7 additions & 3 deletions lib/ContainerLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class ContainerLogger extends EventEmitter {
this._registerToTtyStreams(stdout, stderr);
} else {
this._handleNonTtyStream(stdout, false);
if (stderr) {
this._handleNonTtyStream(stderr, true);
}
}
}, (err) => {
return Q.reject(new CFError({
Expand Down Expand Up @@ -93,9 +96,10 @@ class ContainerLogger extends EventEmitter {
_getLogsStrategyStream() {
return Q.all([
Q.ninvoke(this.containerInterface, 'logs', {
follow: 1,
stdout: 1,
stderr: 1
follow: true,
stdout: true,
stderr: true,
tail: 1000
})
]);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/forever.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
while ($true) {
Start-Sleep -s 1
& node lib/index.js
}
10 changes: 10 additions & 0 deletions lib/isReady.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

CONTAINER_ID=$args[0]

echo "checking if container:$CONTAINER_ID exists"
if ( !$CONTAINER_ID ) {
select-string -Pattern $CONTAINER_ID -Path ./lib/state.json
}
else {
select-string -Pattern "ready" -Path ./lib/state.json
}
13 changes: 0 additions & 13 deletions lib/isReady.sh

This file was deleted.

35 changes: 25 additions & 10 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ class Logger {
this.showProgress = showProgress;

let dockerSockPath;
if (fs.existsSync('/var/run/codefresh/docker.sock')) {
dockerSockPath = '/var/run/codefresh/docker.sock';
//console.log('Using /var/run/codefresh/docker.sock');
if (fs.existsSync('//./pipe/codefresh/docker_engine')) {
dockerSockPath = '//./pipe/codefresh/docker_engine';
} else {
dockerSockPath = '/var/run/docker.sock';
//console.log('Using /var/run/docker.sock');
dockerSockPath = '//./pipe/docker_engine';
}

this.docker = new Docker({
Expand Down Expand Up @@ -182,7 +180,7 @@ class Logger {
* @param docker
* @param newContainer
*/
async _handleContainer(container) { // jshint ignore:line
async _handleContainer(container, loggerStrategy) { // jshint ignore:line
const containerId = container.Id || container.id;
const containerStatus = container.Status || container.status;
const receivedLoggerId = _.get(container, 'Labels', _.get(container, 'Actor.Attributes'))['io.codefresh.logger.id'];
Expand All @@ -191,7 +189,13 @@ class Logger {
const receivedLogSizeLimit = _.get(container,
'Labels',
_.get(container, 'Actor.Attributes'))['io.codefresh.logger.logSizeLimit'];
const loggerStrategy = _.get(container, 'Labels', _.get(container, 'Actor.Attributes'))['io.codefresh.logger.strategy'];
const maxRetryAttempts = 10;
const retryInterval = 1000;
var retryCount = 0;

if (!loggerStrategy) {
loggerStrategy = _.get(container, 'Labels', _.get(container, 'Actor.Attributes'))['io.codefresh.logger.strategy'];
}

if (!containerId) {
logger.error(`Not handling container because id is missing`);
Expand Down Expand Up @@ -258,16 +262,27 @@ class Logger {
containerLogger.once('end', this._handleContainerStreamEnd.bind(this));

containerLogger.start()
.done(() => {
this.state.containers[containerId] = { status: ContainerHandlingStatus.LISTENING };
.then(() => {
this.state[containerId] = { status: ContainerHandlingStatus.LISTENING };
this._writeNewState();
}, (err) => {
})
.catch(async (err) => {
const error = new CFError({
cause: err,
message: `Failed to start logging for container:${containerId}`,
containerId
});
logger.error(error.toString());

if (retryCount !== maxRetryAttempts) {
retryCount++;
logger.warn(`Making another attempt switching to the "${LoggerStrategy.LOGS}" logging strategy`);

await new Promise(r => setTimeout(r, retryInterval));

delete this.state.containers[containerId];
await this._handleContainer(container, LoggerStrategy.LOGS);
}
});
}

Expand Down
Loading