Skip to content
Snippets Groups Projects
Commit 54a14f93 authored by Peter Walter's avatar Peter Walter
Browse files

add k8s deployment

parent f931c63c
No related branches found
No related tags found
No related merge requests found
Pipeline #30755 failed with stages
in 4 minutes and 37 seconds
......@@ -18,6 +18,8 @@ variables:
stages:
- build
- deploy
- deploy_dev
- deploy_prod
build:
stage: build
......@@ -46,7 +48,7 @@ build:
- add-ssh-key ${SSH_OWNER} "${SSH_OWNER_KEY}"
- add-search-domain ebi.ac.uk
deploy_dev: &deploy
deploy_dev: &deploy_vm
<<: *deploy_setup
variables:
NAME: dev
......@@ -65,7 +67,7 @@ deploy_dev: &deploy
url: ${URL}
deploy_live:
<<: *deploy
<<: *deploy_vm
only:
- tags
variables:
......@@ -73,3 +75,70 @@ deploy_live:
URL: ${PROD_URL}
DEST: ${PROD_DEST}
VMS: ${PROD_SERVER}
build_docker:
stage: build
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
before_script:
- export CI_COMMIT_SHA_SHORT=${CI_COMMIT_SHA::8}
- export CI_REGISTRY=dockerhub.ebi.ac.uk
- export IMAGE_NAME=$CI_REGISTRY/$CI_PROJECT_PATH:$CI_COMMIT_SHA_SHORT
script:
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $IMAGE_NAME
# Reusable template, requires the $KUBE_CONFIG and $NAMESPACE variables to be set
# This subsitutes the environment variable $IMAGE_NAME in the overlay file, and deploys
.template: &deploy
image: ebiwd/alpine-ssh:latest
# Can't use the {::8} notation to get a short sha in the variables section, so exporting below
# Also the CI_REGISTRY variable is set incorrectly in GitLab - so exporting to correct value
before_script:
- export CI_COMMIT_SHA_SHORT=${CI_COMMIT_SHA::8}
- export CI_REGISTRY=dockerhub.ebi.ac.uk
- export IMAGE_NAME=$CI_REGISTRY/$CI_PROJECT_PATH:$CI_COMMIT_SHA_SHORT
script:
- mkdir -p $HOME/.kube
- echo -n $KUBE_CONFIG | base64 -d > $HOME/.kube/config
- envsubst '$IMAGE_NAME' < k8s/overlays/caas/ci_image.yaml > file.tmp && mv file.tmp k8s/overlays/caas/ci_image.yaml
- kubectl kustomize k8s/overlays/caas/ | kubectl --namespace=$NAMESPACE apply -f -
deploy_to_hh_dev:
stage: deploy_dev
variables:
NAMESPACE: static-sites-dev
KUBE_CONFIG: $HH_KUBE_CONFIG
<<: *deploy
deploy_to_hx_dev:
stage: deploy_dev
variables:
NAMESPACE: static-sites-dev
KUBE_CONFIG: $HX_KUBE_CONFIG
<<: *deploy
deploy_to_hh_prod:
stage: deploy_prod
only:
- tags
except:
- branches
variables:
NAMESPACE: static-sites-prod
KUBE_CONFIG: $HH_KUBE_CONFIG
<<: *deploy
deploy_to_hx_prod:
stage: deploy_prod
only:
- tags
except:
- branches
variables:
NAMESPACE: static-sites-prod
KUBE_CONFIG: $HX_KUBE_CONFIG
<<: *deploy
FROM ebiwd/node-bower-gulp:6 as builder
WORKDIR /tmp
COPY . /tmp
RUN npm install --quiet && \
bower --allow-root install --quiet && \
npm run build
FROM nginx:1.17.2-alpine
COPY docker-assets/nginx.conf /etc/nginx/nginx.conf
COPY docker-assets/default.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /tmp/dist /usr/share/nginx/html/style-lab
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
index index.html index.htm;
expires 1m;
add_header Cache-Control "public";
}
# caching for static assets
location ~* \.(?:jpg|jpeg|gif|png|ico|xml|css|js)$ {
expires 1d;
add_header Cache-Control "public";
}
#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;
#}
}
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
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;
#tcp_nopush on;
keepalive_timeout 65;
#Enable gzip
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types application/javascript application/rss+xml application/vnd.ms-fontobject application/x-font application/x-font-opentype application/x-font-otf application/x-font-truetype application/x-font-ttf application/x-javascript application/xhtml+xml application/xml font/opentype font/otf font/ttf image/svg+xml image/x-icon text/css text/javascript text/plain text/xml;
#Use relative redirects to avoid issues with ports between different on k8s ingress/services and the pods
absolute_redirect off;
include /etc/nginx/conf.d/*.conf;
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment