New location: openshift and gitlab.
Laziness within sent thoughts of running git clone from inside the container, but eventually decided to give a try to S2I.
First thing, setting an image with a basic nginx service:
.My Dockerfile:
├── build
├── Dockerfile
├── etc
│ ├── nginx.conf
│ ├── server_status.conf
│ └── staticdocs.contoso.com.conf
└── test
└── test-app
└── index.html
FROM my-favourite-repository/centos-7:latest
MAINTAINER Andres Martin <andreu.antonio@gmail.com>
LABEL io.k8s.description="Platform for serving static HTML files" \ io.k8s.display-name="Nginx latest" \
io.openshift.expose-services="8080:http" \ io.openshift.tags="builder,html,nginx"
RUN yum install -y nginx git vim curl && \
yum clean all -y
LABEL io.openshift.s2i.scripts-url=image:///usr/local/s2i
COPY ./.s2i/bin/ /usr/local/s2i
COPY ./etc/nginx.conf /etc/nginx/nginx.conf
COPY ./etc/staticdocs.contoso.com.conf /etc/nginx/conf.d/staticdocs.contoso.com.conf
RUN mkdir -p /etc/nginx/inc.d/internal
COPY ./etc/server_status.conf /etc/nginx/inc.d/internal/server_status.conf
EXPOSE 8080
#copy paste from other Dockerfiles nginxRUN mkdir -p /var/www/html
RUN chmod 777 /var/www/html # because why notRUN mkdir -p /var/log/nginx
RUN chmod g+xrw /var/log/nginxRUN rm -f /etc/nginx/sites-available/default.conf
RUN mkdir /nginx/cache -p
RUN mkdir /nginx/run -p
RUN chmod g+xrw -R /nginx
USER 1001120000
CMD ["/usr/local/s2i/usage"]
My nginx.conf to allow non-privileged execution:
worker_processes 1;After installing the s2i tools, you will have something like this in your folder:
daemon off;
pid /nginx/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 /nginx/access.log main;
error_log /nginx/error.log error;
client_body_temp_path /nginx/cache 1 2;
proxy_temp_path /nginx/cache 1 2;
fastcgi_temp_path /nginx/cache 1 2;
uwsgi_temp_path /nginx/cache 1 2;
sendfile on;
keepalive_timeout 65;
#gzip on;
client_max_body_size 25m;
server_tokens off;
include /etc/nginx/conf.d/*.conf;
index index.html index.htm;
}
├── .s2iAnd you might have this in your run script:
│ └── bin
│ ├── assemble
│ ├── run
│ ├── s2i
│ ├── sti -> s2i
│ └── usage
exec nginx -c /etc/nginx/nginx.confAt this point, to make sure all the above is right you can try a manual run:
Build your image as usual (sudo docker build . -f Dockerfile -t latest --pull; sudo docker tag latest my-registry/builderimagename:latest; sudo docker p
ush my-registry/builderimagename:latest)
$ sudo s2i build <your git repo> <builder image name:test> <result image name:latest>
i.e. my syntax:
$ sudo s2i build https://gitlab.com/myproject.git myrepo/mybuilderimage:latest myrepo/amartin-sample-app
Now is time to configure OpenShift in the next post.
No comments:
Post a Comment