Skip to content

Commit

Permalink
feat(nginx4spa): add spa nginx image (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil authored Nov 12, 2019
1 parent f642a9c commit 1bfd078
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include:
- /helm/.gitlab-ci.yml
- /k8s-ns-killer/.gitlab-ci.yml
- /kubectl/.gitlab-ci.yml
- /spa-nginx/.gitlab-ci.yml
- /nginx4spa/.gitlab-ci.yml

#

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ $ docker pull docker.pkg.github.com/socialgouv/docker/<image>:<version>
| **helm** | `docker pull registry.gitlab.factory.social.gouv.fr/socialgouv/docker/helm:0.9.1` | [![README](https://img.shields.io/badge/README--green.svg)](./helm/README.md) |
| **k8s-ns-killer** | `docker pull registry.gitlab.factory.social.gouv.fr/socialgouv/docker/k8s-ns-killer:0.9.1` | [![README](https://img.shields.io/badge/README--green.svg)](./k8s-ns-killer/README.md) |
| **kubectl** | `docker pull registry.gitlab.factory.social.gouv.fr/socialgouv/docker/kubectl:0.9.1` | [![README](https://img.shields.io/badge/README--green.svg)](./kubectl/README.md) |
| **spa-nginx** | `docker pull registry.gitlab.factory.social.gouv.fr/socialgouv/docker/spa-nginx:0.9.1` | [![README](https://img.shields.io/badge/README--green.svg)](./spa-nginx/README.md) |
| **nginx4spa** | `docker pull registry.gitlab.factory.social.gouv.fr/socialgouv/docker/nginx4spa:0.9.1` | [![README](https://img.shields.io/badge/README--green.svg)](./nginx4spa/README.md) |

<br>
<br>
Expand Down
40 changes: 40 additions & 0 deletions nginx4spa/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Build socialgouv/docker/nginx4spa:
stage: "Build"
extends: .base_register_to_gitlab_stage
variables:
CONTEXT: nginx4spa
IMAGE_NAME: ${CI_REGISTRY_IMAGE}/nginx4spa

Test socialgouv/docker/nginx4spa:
stage: "Test"
image: "${CI_REGISTRY_IMAGE}/nginx4spa:${CI_COMMIT_SHA}"
cache:
key: ${CI_JOB_NAME}-${CI_COMMIT_REF_SLUG}
paths:
- ${CI_PROJECT_DIR}/var/cache/apk
variables:
NGINX_PORT: 8888
VERSION: x.y.z
WWW_DIRECTORY: ${CI_PROJECT_DIR}/nginx4spa/test
script:
- sed -i -e "s|/usr/share/nginx/html|${WWW_DIRECTORY}|g" /etc/nginx/nginx.conf
- sed -i -e "s|80|${NGINX_PORT}|g" /etc/nginx/nginx.conf
- /entrypoint.sh &
- nginx -s stop || pkill nginx || true
#
- nginx
#
- apk --update add curl
- curl -s localhost:${NGINX_PORT}
- curl -s localhost:${NGINX_PORT} |
grep "nginx4spa/test/index.html with VERSION=x.y.z"
- curl -s localhost:${NGINX_PORT}/foo/bar/bar.js
- curl -s localhost:${NGINX_PORT}/foo/bar/bar.js |
grep "// nginx4spa/test/foo/bar/bar.js with VERSION=x.y.z"
#
- kill $(ps aux | grep '[n]ginx' | awk '{print $1}')

Publish socialgouv/docker/nginx4spa to Github Registry:
extends: .base_publish_to_github_stage
variables:
IMAGE_NAME: socialgouv/docker/nginx4spa
3 changes: 2 additions & 1 deletion spa-nginx/Dockerfile → nginx4spa/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM nginx:1.17
FROM nginx:1.17-alpine

COPY ./nginx.conf /etc/nginx/nginx.conf
COPY ./entrypoint.sh /entrypoint.sh
COPY ./envsub.sh /envsub.sh

ENTRYPOINT ["/entrypoint.sh"]
3 changes: 3 additions & 0 deletions nginx4spa/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# KubeCtrl

> KubeCtrl image
5 changes: 5 additions & 0 deletions nginx4spa/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh

source /envsub.sh

exec nginx -g 'daemon off;'
25 changes: 25 additions & 0 deletions nginx4spa/envsub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env sh

################################################################################
# Replace environment values in files #
################################################################################

#
# As defualt, in every files in the "/usr/share/nginx/html" directory, this
# script replace `%%KEY%%` by `VALUE` where `export KEY=VALUE` in the global env var.
#

WWW_DIRECTORY=${WWW_DIRECTORY:="/usr/share/nginx/html"}
DELIMITER=${DELIMITER:="%%"}

# Save env variable in file
printenv > /tmp/env-vars

while IFS='=' read -r KEY VALUE
do
# In every files in the dir, replace the environment variables value
find ${WWW_DIRECTORY} -type f -exec \
sed -i -e "s|${DELIMITER}${KEY}${DELIMITER}|${VALUE}|g" {} \;
done < /tmp/env-vars

rm /tmp/env-vars
8 changes: 4 additions & 4 deletions spa-nginx/nginx.conf → nginx4spa/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ events {


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
absolute_redirect off;
access_log /var/log/nginx/access.log;
default_type application/octet-stream;
error_log /var/log/nginx/error.log;
include /etc/nginx/mime.types;
keepalive_timeout 3000;
absolute_redirect off;
sendfile on;

server {
listen 80;
Expand Down
1 change: 1 addition & 0 deletions nginx4spa/test/foo/bar/bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// nginx4spa/test/foo/bar/bar.js with VERSION=%%VERSION%%
1 change: 1 addition & 0 deletions nginx4spa/test/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nginx4spa/test/index.html with VERSION=%%VERSION%%
18 changes: 0 additions & 18 deletions spa-nginx/.gitlab-ci.yml

This file was deleted.

25 changes: 0 additions & 25 deletions spa-nginx/entrypoint.sh

This file was deleted.

0 comments on commit 1bfd078

Please sign in to comment.