Last active
January 17, 2023 18:28
-
-
Save vinicius73/e7e80e53cabf10e60d8518e27a466457 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream sidecar { | |
server 127.0.0.1:1073; | |
} | |
server { | |
listen 80 default_server; | |
listen [::]:80 default_server; | |
root /usr/share/nginx/html; | |
server_tokens off; | |
merge_slashes off; | |
location /manifest.json { | |
proxy_pass http://sidecar/$host/manifest.json; | |
proxy_redirect off; | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
client_max_body_size 1m; | |
client_body_buffer_size 128k; | |
proxy_connect_timeout 30; | |
proxy_send_timeout 30; | |
proxy_read_timeout 30; | |
} | |
location = /index.html { | |
proxy_pass http://sidecar/$host/index.html; | |
proxy_redirect off; | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
client_max_body_size 1m; | |
client_body_buffer_size 128k; | |
proxy_connect_timeout 30; | |
proxy_send_timeout 30; | |
proxy_read_timeout 30; | |
} | |
# favicon.ico | |
location = /favicon.ico { | |
log_not_found off; | |
access_log off; | |
} | |
# robots.txt | |
location = /robots.txt { | |
log_not_found off; | |
access_log off; | |
} | |
# service worker | |
location = /service-worker.js { | |
expires off; | |
} | |
# assets, media | |
location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ { | |
expires max; | |
access_log off; | |
} | |
# svg, fonts | |
location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff2?)$ { | |
add_header Access-Control-Allow-Origin "*"; | |
expires max; | |
access_log off; | |
} | |
# html files | |
location ~* ^.+\.(html|htm)$ { | |
expires 2m; | |
} | |
location / { | |
try_files $uri $uri/ /index.html; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
APP_VERSION=${BITBUCKET_TAG} | |
BUILD_NUMBER=${BITBUCKET_BUILD_NUMBER:=unknown} | |
BUILDER=${USER}@$(hostname 2> /dev/null && echo $? | tail -0 || echo 'ci') | |
BUILD_DATE=$(date '+%Y-%m-%d__%H:%M:%S') | |
COMMIT=$(git rev-parse HEAD 2> /dev/null && echo $? | tail -0 || echo $BITBUCKET_COMMIT) | |
BRANCH=$(git rev-parse --abbrev-ref HEAD 2> /dev/null && echo $? | tail -0 || echo '') | |
if [ -z "$APP_VERSION" ] | |
then | |
APP_VERSION=$(node -p "require('./package.json').version" 2> /dev/null && echo $? | tail -0 || echo "$BUILD_NUMBER@$BUILD_DATE") | |
fi | |
if [ -z "$BRANCH" ] | |
then | |
BRANCH=${BITBUCKET_TAG:=$BITBUCKET_BRANCH} | |
fi | |
if [ -z "$DOCKER_BUILDKIT" ] | |
then | |
if [ "$DOCKER_BUILDKIT"!='@ci' ] | |
then | |
DOCKER_BUILDKIT=1 | |
fi | |
fi | |
GIT_HASH=${BRANCH}@${COMMIT} | |
echo '@> Building paura image...' | |
echo "@=> APP_VERSION=${APP_VERSION}" | |
echo "@=> GIT_HASH=${GIT_HASH}" | |
echo "@=> BUILDER=${BUILDER}" | |
echo "@=> BUILD_DATE=${BUILD_DATE}" | |
echo "@=> BUILD_NUMBER=${BUILD_NUMBER}" | |
echo "@=> DOCKER_BUILDKIT=${DOCKER_BUILDKIT}" | |
echo '' | |
DOCKER_BUILDKIT=${DOCKER_BUILDKIT} docker build --progress=plain --target=production -t image:tag \ | |
--build-arg APP_VERSION=${APP_VERSION} \ | |
--build-arg GIT_HASH=${GIT_HASH} \ | |
--build-arg BUILDER=${BUILDER} \ | |
--build-arg BUILD_DATE=${BUILD_DATE} \ | |
--build-arg BUILD_NUMBER=${BUILD_NUMBER} \ | |
. | |
echo '@> Done' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM golang:1.15.5-alpine3.12 as sidecar | |
WORKDIR /go/src/app | |
COPY ./docker/sidecar/ ./ | |
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-s -w -extldflags "-static"' -o bin/sidecar . && \ | |
chmod +x ./bin/sidecar | |
FROM node:12.19.0-alpine3.9 as build-stage | |
WORKDIR /app | |
COPY package*.json ./ | |
COPY yarn.lock ./ | |
RUN yarn install | |
COPY . . | |
ARG MODE=production | |
RUN yarn run build --mode $MODE | |
# NGINX | |
FROM nginx:1.19.3-alpine as nginx-stage | |
RUN apk add --no-cache dumb-init tree | |
# copy config | |
COPY docker/nginx/default.conf /etc/nginx/conf.d/default.conf | |
# copy from build | |
COPY --chown=nginx:nginx --from=build-stage /app/dist /usr/share/nginx/html | |
COPY --from=sidecar /go/src/app/bin/sidecar /usr/bin/sidecar | |
COPY docker/nginx/html /usr/share/nginx/html | |
RUN ls -la /usr/share/nginx/html | |
COPY docker/docker-entrypoint.sh / | |
RUN chmod +x /docker-entrypoint.sh | |
ENTRYPOINT ["/usr/bin/dumb-init", "--", "/docker-entrypoint.sh"] | |
# args | |
ARG APP_VERSION=unknown | |
ARG GIT_HASH=unknown | |
ARG BUILDER=unknown | |
ARG BUILD_NUMBER=unknown | |
ARG BUILD_DATE=unknown | |
ARG MODE=production | |
# Labels. | |
LABEL name="x-web-app" \ | |
description="X WEB APP" \ | |
vcs.url="https://bitbucket.org/x/y" \ | |
vcs.ref=$GIT_HASH \ | |
version=$APP_VERSION \ | |
mode=$MODE \ | |
build.date=$BUILD_DATE \ | |
build.number=$BUILD_NUMBER \ | |
build.builder=$BUILDER | |
# Environment | |
ENV GIT_HASH=$GIT_HASH \ | |
APP_VERSION=$APP_VERSION \ | |
BUILD_NUMBER=$BUILD_NUMBER \ | |
BUILD_DATE=$BUILD_DATE \ | |
MODE=$MODE | |
EXPOSE 80 | |
CMD ["http"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
set -u | |
OPTIND=1 | |
ACTION=$1 | |
banner () { | |
echo "BANER..." | |
printf "\n@> Starting web server...\n" | |
echo "@=> APP_VERSION = ${APP_VERSION}" | |
echo "@=> GIT_HASH = ${GIT_HASH}" | |
echo "@=> BUILD_DATE = ${BUILD_DATE}" | |
echo "@=> MODE = ${MODE}" | |
echo '' | |
echo "@=> ACTION = ${ACTION}" | |
echo "" | |
tree /usr/share/nginx/html/ | |
echo "" | |
} | |
startSidecar () { | |
sidecar --root /usr/share/nginx/html/ | |
} | |
httpMode () { | |
startSidecar & nginx -g 'daemon off;' | |
} | |
debugMode () { | |
startSidecar & nginx-debug -g 'daemon off;' | |
} | |
case $ACTION in | |
http) | |
banner && httpMode | |
;; | |
debug) | |
banner && debugMode | |
;; | |
*) | |
exec "$@" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment