Skip to content

Instantly share code, notes, and snippets.

View MiguelTVMS's full-sized avatar

João Miguel Tabosa Vaz Marques Silva MiguelTVMS

View GitHub Profile
@MiguelTVMS
MiguelTVMS / powershell.groovy
Created May 25, 2017 00:29
Groovy script to execute powershell commands on Jenkins
def exec(Map map = [:], command){
def debug = map.debug ?: false
if (debug) echo "[DEBUG] powershell method called with parameter: \n $command"
def returnFileName = new Date().format("yyyyMMddHHmmssSSS")
if (debug) echo "[DEBUG] The return file name will is $returnFileName"
def pwCommand = "powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -Command \"$command\" > $returnFileName"
@MiguelTVMS
MiguelTVMS / windowsservice.groovy
Last active May 25, 2017 00:48
Groovy script to manage windows services on Jenkins
def powershell
def isInstalled(Map map = [:], hostName, serviceName){
def debug = map.debug ?: false
if (debug) echo "[DEBUG] isInstalled method called: hostName:\"$hostName\", serviceName:\"$serviceName\""
def pwret = powershell.exec("(get-service -ComputerName $hostName | Where-Object {\$_.name -eq \\\"$serviceName\\\"})", debug: debug)
def installed = (pwret.trim().length() > 0)
@MiguelTVMS
MiguelTVMS / mongooseValidator.js
Created April 28, 2017 13:17
Helper function to show mongoose validation errors as bad request (409) on express
function mongooseValidator(err, req, res, next) => {
if (err !== 'undefined' && err.name !== 'undefined' && err.name === 'ValidationError')
return handleValidationError(err, res);
if (err !== 'undefined' && err.code === 11000)
return handleDuplicateValidationError(err, res);
next(err);
}
@MiguelTVMS
MiguelTVMS / Dockerfile
Created April 8, 2017 16:19
Rodando NG_PageSpeed & Nginx utilizando Docker - Dockerfile
FROM debian:jessie
RUN apt-get -y update && apt-get install -y \
wget \
build-essential \
libpcre3-dev \
zlib1g-dev
ENV NGINX_VERSION=1.11.12
ENV NPS_VERSION=1.11.33.5
@MiguelTVMS
MiguelTVMS / Dockerfile
Created April 8, 2017 16:14
Rodando NG_PageSpeed & Nginx utilizando Docker - Código 8
ENTRYPOINT \sed -i 's/%%NGX_LOGLEVEL%%/'"$NGX_LOGLEVEL"'/g' /usr/local/nginx/conf/nginx.conf && \
sed -i 's/%%NGX_UPSTREAM_NAME%%/'"$NGX_UPSTREAM_NAME"'/g' /usr/local/nginx/conf/nginx.conf && \
sed -i 's/%%NGX_UPSTREAM_SERVER%%/'"$NGX_UPSTREAM_SERVER"'/g' /usr/local/nginx/conf/nginx.conf && \
sed -i 's/%%NPS_ENABLED%%/'"$NPS_ENABLED"'/g' /usr/local/nginx/conf/nginx.conf && \
sed -i 's/%%NPS_LOWERCASEHTMLNAMES%%/'"$NPS_LOWERCASEHTMLNAMES"'/g' /usr/local/nginx/conf/nginx.conf && \
sed -i 's/%%NPS_ENABLEFILTERS%%/'"$NPS_ENABLEFILTERS"'/g' /usr/local/nginx/conf/nginx.conf && \
sed -i 's/%%NPS_RESPECTVARY%%/'"$NPS_RESPECTVARY"'/g' /usr/local/nginx/conf/nginx.conf && \
sed -i 's/%%NPS_DISABLEREWRITEONNOTRANSFORM%%/'"$NPS_DISABLEREWRITEONNOTRANSFORM"'/g' /usr/local/nginx/conf/nginx.conf && \
sed -i 's/%%NPS_MODIFYCACHINGHEADERS%%/'"$NPS_MODIFYCACHINGHEADERS"'/g' /usr/local/nginx/conf/nginx.conf && \
/usr/local/nginx/sbin/./nginx -g 'daemon off;';
@MiguelTVMS
MiguelTVMS / Dockerfile
Created April 8, 2017 16:13
Rodando NG_PageSpeed & Nginx utilizando Docker - Código 7
# Vamos copiar alguns arquivos para dentro do container.
COPY content/nginx.conf /usr/local/nginx/conf/
COPY content/robots.txt /usr/local/nginx/html/
# Estas linhas servem para que os logs do Nginx sejam apresentadas no console do container.
RUN ln -sf /dev/stdout /usr/local/nginx/logs/access.log
RUN ln -sf /dev/stderr /usr/local/nginx/logs/error.log
@MiguelTVMS
MiguelTVMS / Dockerfile
Created April 8, 2017 16:09
Rodando NG_PageSpeed & Nginx utilizando Docker - Código 6
# Estas são as configurações que utilizamos no nginx.
ENV NGX_LOGLEVEL debug
ENV NGX_UPSTREAM_NAME www.google.com
ENV NGX_UPSTREAM_SERVER www.google.com:80
# Estas são as configurações que utilizaremos no PageS
ENV NPS_ENABLED on
ENV NPS_LOWERCASEHTMLNAMES on
ENV NPS_RESPECTVARY off
ENV NPS_DISABLEREWRITEONNOTRANSFORM on
@MiguelTVMS
MiguelTVMS / Dockerfile
Created April 8, 2017 16:07
Rodando NG_PageSpeed & Nginx utilizando Docker - Código 5
# Removendo todo o código fonte baixado para a compilação.
RUN rm -rf /usr/nginx_source
# Limpando os pacotes desnecessários para e execução do container.
RUN apt-get purge -y \
wget \
build-essential \
libpcre3-dev \
zlib1g-dev \
&& apt-get autoremove -y
@MiguelTVMS
MiguelTVMS / Dockerfile
Created April 8, 2017 15:57
Rodando NG_PageSpeed & Nginx utilizando Docker - Código 4
# Compilando o Nginx
WORKDIR "/usr/nginx_source/nginx-$NGINX_VERSION/"
RUN ./configure \
--add-module=/usr/nginx_source/ngx_pagespeed-latest-stable \
--add-module=/usr/nginx_source/ngx_http_substitutions_filter_module-$SUBS_VERSION
RUN make
RUN make install
@MiguelTVMS
MiguelTVMS / Dockerfile
Created April 8, 2017 15:55
Rodando NG_PageSpeed & Nginx utilizando Docker - Código 3
ENV NGINX_VERSION=1.11.12
ENV NPS_VERSION=1.11.33.5
ENV PSOL_VERSION=1.11.33.4
ENV SUBS_VERSION=0.6.4
# Criamos a pasta que conterá o nosso código fonte.
RUN ["mkdir","/usr/nginx_source/"]
WORKDIR "/usr/nginx_source/"
# Baixamos o código do Nginx da versão que selecionamos.