Merge branch '166-setup-dev-ci-cd' into 'develop'

Draft: Resolve "setup dev CI/CD"

See merge request framasoft/framadate/funky-framadate-front!81
This commit is contained in:
Benoit Martins 2023-06-08 06:17:56 +00:00
commit 1af5ceae98
5 changed files with 201 additions and 11 deletions

8
.dockerignore Normal file
View File

@ -0,0 +1,8 @@
.angular/
node_modules/
dist/
docs/
e2e/
**/*.log
**/.DS_Store
**/Thumbs.db

View File

@ -1,16 +1,19 @@
# image: weboaks/node-karma-protractor-chrome
image: node:16
# image: node:16
include:
- "kaniko-build.gitlab-ci.yml"
stages:
- build
- deploy
# - pages
# - test
# - e2e
cache:
paths:
- node_modules/
- .yarn
# cache:
# paths:
# - node_modules/
# - .yarn
#pages:
# stage: pages
@ -37,14 +40,39 @@ cache:
# cache:
# policy: pull
build:
build-image:
stage: build
before_script:
- yarn
tags:
- docker
extends: .kaniko_build
variables:
PUSH_IMAGE: "true"
REGISTRY_PATH: "${HARBOR_HOST}/${HARBOR_PROJECT}"
REGISTRY_IMAGE_PATH: "${REGISTRY_PATH}/${CI_PROJECT_NAME}:develop"
only:
- develop
deploy-image:
stage: deploy
image:
name: bitnami/kubectl:latest
entrypoint: ['']
script:
- yarn run build:prod
cache:
policy: pull
- kubectl config get-contexts
- kubectl config use-context framasoft/framadate/funky-framadate-front:framadate-cluster
- kubectl -n framadate rollout restart deployments/frontend-deployment
only:
- develop
# build:
# image: node:16
# stage: build
# before_script:
# - yarn
# script:
# - yarn run build:prod
# cache:
# policy: pull
#e2e:
# stage: e2e

27
Dockerfile Normal file
View File

@ -0,0 +1,27 @@
# Create stage to build angular application
FROM node:18.15.0-alpine AS angular-builder
WORKDIR /app
COPY package.json .
RUN yarn install
COPY . .
RUN yarn run build:prod
# Build NGINX Image to serve builded files
FROM nginx:stable-alpine
WORKDIR /app
RUN rm -rf /usr/share/nginx/html/*
COPY docker/nginx/nginx.conf /etc/nginx/nginx.conf
# Copy dist folder fro build stage to nginx public folder
COPY --from=angular-builder /app/dist/framadate /app
# Start NgInx service
CMD ["nginx", "-g", "daemon off;"]

58
docker/nginx/nginx.conf Normal file
View File

@ -0,0 +1,58 @@
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /tmp/nginx.pid;
events {
worker_connections 1024;
}
http {
client_body_temp_path /tmp/client_temp;
proxy_temp_path /tmp/proxy_temp_path;
fastcgi_temp_path /tmp/fastcgi_temp;
uwsgi_temp_path /tmp/uwsgi_temp;
scgi_temp_path /tmp/scgi_temp;
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_static on;
gzip_vary on;
gzip_proxied no-cache no-store private expired auth;
gzip_min_length 10240;
gzip_types
application/javascript
application/json
font/woff2
text/css
text/plain;
server {
listen 80;
server_name localhost;
location / {
root /app;
index index.html;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~* (\.html|\/sw\.js)$ {
root /app;
expires -1y;
add_header Pragma "no-cache";
add_header Cache-Control "public";
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|json)$ {
root /app;
expires 1y;
add_header Cache-Control "public, immutable";
}
}
}

View File

@ -0,0 +1,69 @@
# FROM https://gitlab.cern.ch/ci-tools/container-image-ci-templates/
# Defining the variables which can be overridden while using the template file in .gitlab-ci.yml
# REGISTRY_IMAGE_PATH: Defines where the image should be pushed to.
# CONTEXT_DIR: Defines the context dir for the image build
# DOCKER_FILE_NAME: Defines the name of the Dockerfile
# PUSH_IMAGE: If the gitlab step should push the built image
# BUILD_ARGS: The build-time variables
variables:
CONTEXT_DIR: ""
DOCKER_FILE_NAME: "Dockerfile"
GIT_SUBMODULE_STRATEGY: recursive
PUSH_IMAGE: "false"
BUILD_ARGS: ""
.kaniko_build:
stage: build
tags:
- docker
image:
# Using the official kaniko v1.6 image for the builds
name: gcr.io/kaniko-project/executor:v1.6.0-debug
entrypoint: [""]
script:
- |
if [ -z "${REGISTRY_IMAGE_PATH}" ]; then
echo "ERROR: CI variable REGISTRY_IMAGE_PATH is mandatory."
exit 1
fi
- REGISTRY=$(echo ${REGISTRY_IMAGE_PATH} | cut -d / -f 1)
- >
if [ -z "${CONTEXT_DIR}" ]; then
KANIKO_CONTEXT_DIR=${CI_PROJECT_DIR}
else
KANIKO_CONTEXT_DIR=${CI_PROJECT_DIR}/${CONTEXT_DIR}
fi
- mkdir -p /kaniko/.docker
- |
if [ -z "$DOCKER_AUTH_CONFIG" ]; then
# build the DOCKER_AUTH_CONFIG from user parameters as per https://docs.gitlab.com/ee/ci/docker/using_kaniko.html and internal docs
echo "{\"auths\":{\"${HARBOR_HOST}\":{\"auth\":\"$(printf "%s:%s" "${HARBOR_USERNAME}" "${HARBOR_PASSWORD}" | base64 | tr -d '\n')\"}}}" > /kaniko/.docker/config.json
else
echo "${DOCKER_AUTH_CONFIG}" > /kaniko/.docker/config.json
fi
# build and push the image to the path set in $REGISTRY_IMAGE_PATH variable.
- |
if [ "$(echo ${PUSH_IMAGE} | tr '[:upper:]' '[:lower:]')" = "true" ]; then
PUSH_IMAGE=""
else
echo "Info: defer pushing image to remote as PUSH_IMAGE is false"
PUSH_IMAGE="--no-push"
fi
- |
if [ -n "$BUILD_ARGS" ]; then
for arg in $BUILD_ARGS; do
KANIKO_BUILD_ARGS="${KANIKO_BUILD_ARGS} --build-arg ${arg}"
done
fi
- /kaniko/executor
--cache=true
--cache-repo=${REGISTRY_PATH}/cache
--context "${KANIKO_CONTEXT_DIR}"
--dockerfile "${DOCKER_FILE_PATH}/${DOCKER_FILE_NAME}" ${KANIKO_BUILD_ARGS}
--destination "${REGISTRY_IMAGE_PATH}" "${PUSH_IMAGE}"
--use-new-run
--single-snapshot
--snapshotMode=redo
--skip-unused-stages