Skip to content

Commit

Permalink
MODIFIED:
Browse files Browse the repository at this point in the history
complete full go rewrite
added environment variables to control the container at runtime
  • Loading branch information
dgutierrez1287 committed Mar 18, 2018
1 parent fd2a6f0 commit 99039cd
Show file tree
Hide file tree
Showing 13 changed files with 311 additions and 154 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea/**
.idea/**
logs/**
repo/**
44 changes: 32 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
# build stage
FROM golang:1.8.3 as builder

WORKDIR /go/src/github.com/dgutierrez1287/docker-yum-repo

RUN go get -d -v github.com/Sirupsen/logrus && \
go get -d -v github.com/rjeczalik/notify && \
go get -d -v gopkg.in/dickeyxxx/golock.v1 && \
go get -d -v gopkg.in/natefinch/lumberjack.v2

COPY src/*.go .

RUN GOOS=linux go build -x -o repoScanner .

# application image
FROM centos:7
MAINTAINER Diego Gutierrez <dgutierrez1287@gmail.com>
LABEL maintainer="Diego Gutierrez <dgutierrez1287@gmail.com>"

RUN yum -y install epel-release && yum clean all
RUN yum -y update && yum clean all
RUN yum -y install ruby gcc ruby-devel supervisor createrepo yum-utils nginx && yum clean all
RUN gem install rb-inotify
RUN yum -y install epel-release && \
yum -y update && \
yum -y install supervisor createrepo yum-utils nginx && \
yum clean all

RUN mkdir /root/repo
RUN mkdir /root/logs
RUN mkdir /repo && \
chmod 777 /repo && \
mkdir -p /logs

COPY nginx.conf /etc/nginx/nginx.conf
COPY supervisord.conf /etc/supervisord.conf
COPY scan_repo.rb /root/scan_repo.rb
COPY --from=builder /go/src/github.com/dgutierrez1287/docker-yum-repo/repoScanner /root/

RUN chmod 700 /root/scan_repo.rb
RUN chmod 700 /root/repoScanner

EXPOSE 80
VOLUME /root/repo /root/logs
VOLUME /repo /logs

ENV DEBUG false
ENV LINUX_HOST true
ENV SERVE_FILES true

COPY entrypoint.sh /root/entrypoint.sh
RUN chmod 700 entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
RUN chmod 700 /root/entrypoint.sh
ENTRYPOINT ["/root/entrypoint.sh"]



Expand Down
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Docker-Yum-Repo

docker-yum-repo builds a yum repo server to run in a docker container. It is built
off of CentOS 7 and will update the repo automatically when an rpm is added or removed
courtesy of a custom ruby script using [rb-inotify](https://github.com/nex3/rb-inotify)
courtesy of a custom repo scanner written in go using [rjeczalik/notify](https://github.com/rjeczalik/notify)


## Install
Expand All @@ -24,7 +24,19 @@ docker run -d -p 8080:80 -v /opt/repo:/repo dgutierrez1287/yum-repo
### Mapping Logs

There is a log volume (/logs) that can be mapped to the host machine. In that directory
nginx, supervisord and the custom rudy script (repo_scanner) will log to subdirectories.
nginx, supervisord and the custom go program (repoScanner) will log to subdirectories.

### Environment Variables

There are three environment variables that can be set to change the operation of the repoScanner and the entrypoint script to configure the container at runtime

DEBUG (String, Default: 'true') - This will enable debug logging for the repo scanner program, this should only be run for debugging since the log is very chatty.

LINUX_HOST (String, Default: 'true') - This container should be run on a linux host for production in which case this should be true, if you wanted to test this on docker for Windows or docker for Mac set this to false. I have found that Docker on a non linux platform will only send the file system notifications available for that system which is a subset of what is available for Linux. This setting will change the repo scanner to only look for the notifications available from Windows and Mac (if its false) or the notifications only available from Linux machines (if its true).

Note: When running in non linux host mode the create repo tasks will fire more then once even if there is only one file placed in a repo directory, this is because the notifications available for non linux hosts are not a precise as the ones for Linux hosts. please see https://godoc.org/github.com/rjeczalik/notify for more detail.

SERVE_FILES (String, Default 'true') - This will stop nginx on the container from starting, this should be used if you only want to use the repo scanner portion of the container and will serve the files some other way. This could be accomplished by not mapping the port but this will set nginx to not run thereby saving a few extra resources.

### Using the Repo Directory

Expand All @@ -43,4 +55,18 @@ let me know any issues that come up with the image or make an issue on the

### Contributing
You are invited to contribute any new features or fixes; and I am happy to receive pull
requests.
requests.

## Disclaimer

This module is provided without warranty of any kind, the creator(s) and contributors do their best to ensure stablity but can make no warranty about the stability of this docker image in different environments. The creator(s) and contributors reccomend that you test this image and all future releases of this image in your environment before use.

## ChangeLog

Version: 1.0.0, 2017-03-22

This initial release happened months ago however since I am going to be making some heavy changes I figured I would tag it to maintain the point in time.

Version: 2.0.0, 2018-03-18

This is almost a full re-write with many new features. The ruby script has been replaced by a go program, which will do an inital scan at start up and uses concurrency and file locking. I have added multi-stage build process for the container to bring down the final container size. I have also added controls for not enabling nginx (if file serving will be done another way and to save resouces) amd turning on debugging.
10 changes: 0 additions & 10 deletions build/build.sh

This file was deleted.

2 changes: 0 additions & 2 deletions build/release.sh

This file was deleted.

4 changes: 3 additions & 1 deletion changeLog.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Version: 1.0.0
Version: 1.0.0, 2017-03-22
This initial release happened months ago however since I am going to be making some heavy changes I figured I would tag it to maintain the point in time.
Version: 2.0.0, 2018-03-18
This is almost a full re-write with many new features. The ruby script has been replaced by a go program, which will do an inital scan at start up and uses concurrency and file locking. I have added multi-stage build process for the container to bring down the final container size. I have also added controls for not enabling nginx (if file serving will be done another way and to save resouces) amd turning on debugging.
27 changes: 23 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
#!/bin/bash

mkdir /root/logs/repo-scanner
mkdir /root/logs/nginx
mkdir /root/logs/supervisord
mkdir /logs/repo-scanner
mkdir /logs/nginx
mkdir /logs/supervisord

chown nginx:nginx /root/logs/nginx
chown nginx:nginx /logs/nginx

chmod -R 0755 /repo

if [[ "${SERVE_FILES}" == "true" ]]; then
echo "Serving Files is on"
cat << EOF >> /etc/supervisord.conf
[program:nginx]
priority=10
directory=/
command=/usr/sbin/nginx -c /etc/nginx/nginx.conf -g "daemon off;"
user=root
autostart=true
autorestart=true
stopsignal=QUIT
redirect_stderr=true
EOF
else
echo "Serving Files is off"
fi

exec /usr/bin/supervisord -n -c /etc/supervisord.conf
4 changes: 2 additions & 2 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ http {
listen 80 default_server;

location /{
autoindex on;
alias /repo/;
autoindex on;
alias /repo/;
}

access_log /logs/nginx/access.log;
Expand Down
40 changes: 0 additions & 40 deletions scan_repo.rb

This file was deleted.

Loading

0 comments on commit 99039cd

Please sign in to comment.