Skip to content
Snippets Groups Projects
Commit 641e92c2 authored by Bartek Wrona's avatar Bartek Wrona
Browse files

WIP: initial setup of nginx container to serve app

parent a386c38f
Branches bw_nginx_image
No related tags found
No related merge requests found
Pipeline #118418 passed
ARG NGNIX_VERSION=mainline-alpine3.21
FROM nginxinc/nginx-unprivileged:$NGNIX_VERSION AS app
USER root
COPY ./dist /usr/share/nginx/html/
#RUN rm /usr/share/nginx/html/_redirects
RUN cat > /etc/nginx/sites-available/default <<EOF
server {
listen 8080;
server_name localhost;
access_log /var/log/nginx/host.access.log ;
error_log /var/log/nginx/host.error.log ;
location / {
root /usr/share/nginx/html;
#index index.html index.htm;
#include /etc/nginx/mime.types;
try_files $uri $uri/ /index.html;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/html;
#}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
EOF
USER nginx
ARG BUILD_TIME
ARG GIT_COMMIT_SHA
ARG GIT_CURRENT_BRANCH
ARG GIT_LAST_LOG_MESSAGE
ARG GIT_LAST_COMMITTER
ARG GIT_LAST_COMMIT_DATE
LABEL org.opencontainers.image.created="$BUILD_TIME"
LABEL org.opencontainers.image.url="https://hive.io/"
LABEL org.opencontainers.image.documentation="https://gitlab.syncad.com/hive/wallet-dapp"
LABEL org.opencontainers.image.source="https://gitlab.syncad.com/hive/wallet-dapp"
#LABEL org.opencontainers.image.version="${VERSION}"
LABEL org.opencontainers.image.revision="$GIT_COMMIT_SHA"
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.ref.name="Metamask dApp providing a bridge to Hive blockchain"
LABEL org.opencontainers.image.title="Hive Bridge Application Image"
LABEL org.opencontainers.image.description="Runs Hive Bridge applicaton)"
LABEL io.hive.image.branch="$GIT_CURRENT_BRANCH"
LABEL io.hive.image.commit.log_message="$GIT_LAST_LOG_MESSAGE"
LABEL io.hive.image.commit.author="$GIT_LAST_COMMITTER"
LABEL io.hive.image.commit.date="$GIT_LAST_COMMIT_DATE"
#! /bin/bash
set -euo pipefail
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
SCRIPTSDIR="$SCRIPTPATH/.."
print_help () {
cat <<-EOF
Usage: $0 <image_tag> <src_dir> <registry_url> [OPTION[=VALUE]]...
Builds docker image containing Transaction Inspector application installation, ready to run. To spawn it, just run a container and map port 8080 to the host.
OPTIONS:
--help|-h|-? Display this help screen and exit
--progress=TYPE Determines how to display build progress (default: 'auto')
--push Allows to automatically push built image to the registry
EOF
}
PROGRESS_DISPLAY=${PROGRESS_DISPLAY:-"auto"}
IMAGE_OUTPUT="--load"
BUILD_IMAGE_TAG=""
REGISTRY=""
SRCROOTDIR=""
while [ $# -gt 0 ]; do
case "$1" in
--help|-h|-?)
print_help
exit 0
;;
--progress=*)
arg="${1#*=}"
PROGRESS_DISPLAY="$arg"
;;
--push)
IMAGE_OUTPUT="--push"
;;
*)
if [ -z "$BUILD_IMAGE_TAG" ];
then
BUILD_IMAGE_TAG="${1}"
elif [ -z "$SRCROOTDIR" ];
then
SRCROOTDIR="${1}"
elif [ -z "$REGISTRY" ];
then
REGISTRY=${1}
else
echo "ERROR: '$1' is not a valid option/positional argument"
echo
print_help
exit 2
fi
;;
esac
shift
done
_TST_IMGTAG=${BUILD_IMAGE_TAG:?"Missing arg #1 to specify built image tag"}
_TST_SRCDIR=${SRCROOTDIR:?"Missing arg #2 to specify source directory"}
_TST_REGISTRY=${REGISTRY:?"Missing arg #3 to specify target container registry"}
# Supplement a registry path by trailing slash (if needed)
#[[ "${REGISTRY}" != */ ]] && REGISTRY="${REGISTRY}/"
echo "Moving into source root directory: ${SRCROOTDIR}"
pushd "$SRCROOTDIR"
export DOCKER_BUILDKIT=1
BUILD_TIME="$(date -uIseconds)"
GIT_COMMIT_SHA="$(git rev-parse HEAD || true)"
if [ -z "$GIT_COMMIT_SHA" ]; then
GIT_COMMIT_SHA="[unknown]"
fi
GIT_CURRENT_BRANCH="$(git branch --show-current || true)"
if [ -z "$GIT_CURRENT_BRANCH" ]; then
GIT_CURRENT_BRANCH="$(git describe --abbrev=0 --all | sed 's/^.*\///' || true)"
if [ -z "$GIT_CURRENT_BRANCH" ]; then
GIT_CURRENT_BRANCH="[unknown]"
fi
fi
GIT_LAST_LOG_MESSAGE="$(git log -1 --pretty=%B || true)"
if [ -z "$GIT_LAST_LOG_MESSAGE" ]; then
GIT_LAST_LOG_MESSAGE="[unknown]"
fi
GIT_LAST_COMMITTER="$(git log -1 --pretty="%an <%ae>" || true)"
if [ -z "$GIT_LAST_COMMITTER" ]; then
GIT_LAST_COMMITTER="[unknown]"
fi
GIT_LAST_COMMIT_DATE="$(git log -1 --pretty="%aI" || true)"
if [ -z "$GIT_LAST_COMMIT_DATE" ]; then
GIT_LAST_COMMIT_DATE="[unknown]"
fi
echo -e "\nBuilding base instance image...\n"
docker buildx build --target=app \
--progress="$PROGRESS_DISPLAY" \
--build-arg BUILD_TIME="$BUILD_TIME" \
--build-arg GIT_COMMIT_SHA="$GIT_COMMIT_SHA" \
--build-arg GIT_CURRENT_BRANCH="$GIT_CURRENT_BRANCH" \
--build-arg GIT_LAST_LOG_MESSAGE="$GIT_LAST_LOG_MESSAGE" \
--build-arg GIT_LAST_COMMITTER="$GIT_LAST_COMMITTER" \
--build-arg GIT_LAST_COMMIT_DATE="$GIT_LAST_COMMIT_DATE" \
--tag "${REGISTRY}:${BUILD_IMAGE_TAG}" \
"${IMAGE_OUTPUT}" \
--file Dockerfile.nginx "$SRCROOTDIR"
echo -e "\nDone!\nBuilding instance image...\n"
echo "APP_IMAGE_NAME=$REGISTRY:$BUILD_IMAGE_TAG" > app_docker_image_name.env
{
echo "APP_IMAGE_VERSION=$BUILD_IMAGE_TAG"
} >> app_docker_image_name.env
popd
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment