diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 92f0d8cba2f6fc194c077618d06ef82b0ab59b42..bb5d61cbe3f2fd867dfd33e9eee06fd3fb71cb56 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..62812327e5a933dfd7c74c745ab915fc592ae287 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +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 diff --git a/docker-assets/default.conf b/docker-assets/default.conf new file mode 100644 index 0000000000000000000000000000000000000000..9724bd686406ee19ad10ab6429a950543a9fb550 --- /dev/null +++ b/docker-assets/default.conf @@ -0,0 +1,54 @@ +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; + #} +} + diff --git a/docker-assets/nginx.conf b/docker-assets/nginx.conf new file mode 100644 index 0000000000000000000000000000000000000000..4b699e51c1df37dfa47a355d0a1610e95f3f6691 --- /dev/null +++ b/docker-assets/nginx.conf @@ -0,0 +1,43 @@ + +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; +}