Skip to content

Commit 6ea42c9

Browse files
committed
Establish Docker-registry:2 with simple ui
1 parent 21039f9 commit 6ea42c9

File tree

9 files changed

+105
-33
lines changed

9 files changed

+105
-33
lines changed

README.md

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ My personal solution is a local, docker-based CI/CD Build Environment ready in a
1010
* docker
1111
* Gitlab
1212
* and a docker based gitlab-runner registrated
13-
* suecured docker-registry ready (openssh certificate)
13+
* secured docker-registry ready (openssh certificate)
1414
* push with ssh avialable at port 2222
1515
* Nexus 3
1616
* Sonar
17-
* Keykloak (as Single Sign or JWT playground)
18-
* Postgres (used by sonar, keycloak and YOUR applications)
17+
* Keykloak (as Single Sign On or JWT playground)
18+
* Postgres (used by Sonar, Keycloak and YOUR applications)
19+
* Standard Docker-Registry V2 with a simple UI
20+
21+
1922

2023
so you can be your own local "DevOp"; nearly every category of [periodic table of devoptools][4] has one tool in your local setup.
2124

@@ -30,10 +33,11 @@ so you can be your own local "DevOp"; nearly every category of [periodic table o
3033

3134
|Port | Why |
3235
|---|---|
33-
|80 |NGINX |
34-
|5432 |postgres standard |
35-
|2222 |ssh port of gitlab, used to push via ssh connection |
36-
|5555 |Gitlab Docker-registry |
36+
|80 |NGINX, forwards requests ton internal docker-containers |
37+
|5432 |postgres standard connection port |
38+
|2222 |ssh port of gitlab, used to push via ssh connection ssh://git@myHOST:2222/scott/foo.git |
39+
|5555 |Gitlab docker-registry secured with GitLab credentials |
40+
|5000 |Standard Docker-Registry v2 not secured|
3741

3842
If your change the ports in the docker-compose.yml change them also in nginx-reverse/nginx.conf (stream {...} )
3943
## Installation
@@ -78,6 +82,7 @@ Now you are ready to go with a little CI/CD Environment:
7882
Gitlab http://<your-host-name>/gitlab
7983
Sonar http://<your-host-name>/sonar
8084
Keycloak http://<your-host-name>/auth
85+
Docker-Registry-Ui: http://<your-host-name>/regweb
8186
Postgres: At standard listenport 5432 for your jdbc-connection-string
8287
stream-passthrough to postgres-container.
8388
```
@@ -99,6 +104,9 @@ See Readme in folder security-paranoia if you want to have some hints how to con
99104
|Postgres|postgres|admin|
100105

101106
## The Tools
107+
There are some configurations you have to do after setup.
108+
*Remember:* At every time use your real hostname and NOT localhost (locahost inside a container is the container itself).
109+
For example: If yuo configure a GitLab-Connection in Jenkins, you will reach Gitlab at http://&lt;you host&gt;/gitlab and not http://localhost/gitlab
102110
### Jenkins
103111
* MAVEN_HOME is /opt/maven
104112
* JAVA_HOME is /usr/lib/jvm/java-8-openjdk-amd64
@@ -109,10 +117,10 @@ See Readme in folder security-paranoia if you want to have some hints how to con
109117
* the docker-registry from GitLab is at port 5555 (and secured with an openssl certificate ..thats part of
110118
setupEnvironment.sh), just create a project in gitlab and click at the registry tab to show
111119
how to login to the project registry and how to tag your images and upload them.
112-
* ssh cloning and pushing is at port 2222
120+
* ssh cloning and pushing is at port 2222 (ssh://git@myHOST:2222/scott/foo.git remeber to upload your public key before, should be ~/.ssh/id_rsa.pub )
113121

114122
#### gitlab-runner
115-
The runner is a gitlab-multirunner image with a docker-runner (concurrent=1) , based on [gitlab/gitlab-runner][2] at every startup any runner is removed and only ONE new runner ist registrated to avoid multiple runners (the pipeline-history maybe lost.) docker-in-docker works :-)
123+
The runner is a gitlab-multirunner image with a docker-runner (concurrent=1) , based on [gitlab/gitlab-runner][2] at every startup any runner is removed and only ONE new runner is registrated to avoid multiple runners (the pipeline-history maybe lost.) docker-in-docker works :-)
116124

117125
It takes a long time until gitlab is ready to accept a runner registration, if it fails, increase the REGISTER_TRYS in docker-compse.yml
118126

@@ -136,34 +144,35 @@ _tl;dr_
136144
* create client "product-app" as openid-connect client with Valid Redirect URI's http://&lt;your host&gt;:8081/*
137145
* create role "user"
138146
* create user "testuser" and map the role "user" to testuser (tab Role Mappings)
139-
140-
### Nexus
141-
Some ToDo for me described here
142-
[Unsecure docker-registry in Nexus][1]
143-
use GitLab as a secured registry
144-
..
145-
And _yes_ docker-plugin in jenkins works (docker in docker, usefull but not recommended)
147+
148+
146149
### Postgres
147-
You can use any tool to connect to the database at locahost:5432 this is a pass through to the container so any
150+
You can use any tool to connect to the database at localhost:5432 this is a pass through to the container so any
148151
JDBC-Connection should work
149152

153+
### The Docker-Registries
154+
* NEXUS-Docker-Registry ist NOT configured .. needs a pass trough and some more configs, see [Unsecure docker-registry in Nexus][1] feel free to provide a push-request
155+
* GitLab docker-registry is at port 5555 you have to use your GitLab Credentials from the corresponding git-respository
156+
* standard Docker-Registry v2 ist at standard port 5000 with no credentials, so eays-to-use
157+
158+
150159
## Troubleshooting
151160
##### check Hostname and IP
152161
In most cases a wrong HOSTNAME:HOSTIP causes trouble, to check this try the following.
153162
* log into the jenkins-fat container (with id)
154163
```
155164
docker container ls
156-
docker container exec -it dockerlocalbuildenvironment_jenkins_1 bash
165+
docker container exec -it jenkins-fat bash
166+
chmod a+rw /tmp
157167
apt-get update
158168
apt-get install -y --allow-unauthenticated iputils-ping
159-
ping google.de
160169
ping jenkins
161170
ping gitlab
162171
ping <your local hostname>
163172
```
164173
every ping must work, if not, check the .env file, is there the correct DC_HOSTNAME / DC_HOSTIP ?
165174

166-
##### changed networks ?
175+
##### changed interface ip ?
167176
If you change your network (switching between home/office/lan/wifi) your ip-address
168177
could be change and the container is not able to resolve your host any more
169178
Check the .env file or just run the setup-Script again.
@@ -185,7 +194,7 @@ every ping must work, if not, check the .env file, is there the correct DC_HOSTN
185194
* ~~apply git-lfs~~
186195
* ~~apply sonar~~
187196
* ~~apply keycloak~~
188-
* apply a better registry
197+
* ~~apply a better registry~~
189198

190199

191200

docker-compose-keycloak.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ version: "3"
66
services:
77
keycloak:
88
image: jboss/keycloak
9+
container_name: jboss-keycloak
910
environment:
1011
- KEYCLOAK_USER=admin
1112
- KEYCLOAK_PASSWORD=admin

docker-compose-sonar.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ version: "3"
77
services:
88
sonar:
99
image: sonarqube
10+
container_name: sonarcube
1011
depends_on: # start proxy after all the others
1112
- postgres
1213
extra_hosts:

docker-compose.yml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,46 @@ networks:
1414
services:
1515
# ------------------------------------------------------------------------------
1616
ngnix:
17+
container_name: nginx-reverse
1718
build: nginx-reverse
1819
ports:
19-
- "80:80" #http://
20-
- "5432:5432" # Default-Port of the Postges DB passing jdbc-Connections to the postgres-Container
21-
- "2222:2222" #ssh port of gitlab (ssh://git@myHOST:2222/scott/foo.git)
22-
- "5555:5555" #Gitlab Docker Registry do NOT use 5000, this is an internal PORT of the gitlab-ce Image
23-
command: ["nginx-debug", "-g", "daemon off;"] # Start nginx in debug to see whats going on
20+
- 80:80 # http://
21+
- 5432:5432 # Default-Port of the Postges DB passing jdbc-Connections to the postgres-Container
22+
- 2222:2222 # ssh port of gitlab (ssh://git@myHOST:2222/scott/foo.git)
23+
- 5555:5555 # Gitlab Docker Registry do NOT use 5000, this is an internal PORT of the gitlab-ce Image
24+
#command: ["nginx-debug", "-g", "daemon off;"] # Start nginx in debug to see whats going on
2425
depends_on: # start proxy after all the others
2526
- gitlab
2627
- jenkins
2728
- nexus
2829
networks:
2930
- devstacknetwork
31+
# ------------------------------------------------------------------------------
32+
regweb:
33+
container_name: docker-registry-web
34+
image: hyper/docker-registry-web
35+
networks:
36+
- devstacknetwork
37+
extra_hosts:
38+
- ${DC_HOSTNAME}:${DC_HOSTIP}
39+
environment:
40+
- REGISTRY_URL=http://${DC_HOSTNAME}:5000/v2
41+
- REGISTRY_NAME=Your docker-local-build-registry@${DC_HOSTNAME}:5000
42+
- REGISTRY_READONLY=false
43+
- REGISTRY_CONTEXT_PATH=/regweb
44+
# ------------------------------------------------------------------------------
45+
registry:
46+
container_name: registry
47+
image: registry:2
48+
network_mode: "host"
49+
ports:
50+
- 5000:5000
51+
volumes:
52+
- ${DC_BASE_DATA_DIR}/docker-registry/config.yml:/etc/docker/registry/config.yml
53+
- ${DC_BASE_DATA_DIR}/docker-registry/images:/var/lib/registry
3054
# ------------------------------------------------------------------------------
3155
postgres:
56+
container_name: postgres
3257
build: postgres
3358
extra_hosts:
3459
- ${DC_HOSTNAME}:${DC_HOSTIP}
@@ -48,6 +73,7 @@ services:
4873

4974
jenkins:
5075
build: jenkins-fat
76+
container_name: jenkins-fat
5177
extra_hosts:
5278
- ${DC_HOSTNAME}:${DC_HOSTIP}
5379
networks:
@@ -59,6 +85,7 @@ services:
5985
# ------------------------------------------------------------------------------
6086
gitlab:
6187
image: 'gitlab/gitlab-ce:latest'
88+
container_name: gitlab-ce
6289
extra_hosts:
6390
- ${DC_HOSTNAME}:${DC_HOSTIP}
6491
networks:
@@ -87,6 +114,7 @@ services:
87114
# ------------------------------------------------------------------------------
88115
nexus:
89116
image: sonatype/nexus3
117+
container_name: sonatype-nexus3
90118
extra_hosts:
91119
- ${DC_HOSTNAME}:${DC_HOSTIP}
92120
networks:
@@ -99,6 +127,7 @@ services:
99127
# ------------------------------------------------------------------------------
100128
gitlabrunner:
101129
build: gitlabrunner
130+
container_name: gitlabrunner
102131
network_mode: "host"
103132
extra_hosts:
104133
- ${DC_HOSTNAME}:${DC_HOSTIP}

jenkins-fat/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/active-plugins.txt_SAVE

jenkins-fat/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ ENV JAVA_VERSION=8 \
66
JAVA_HOME="/usr/lib/jvm/default-jvm"
77

88
# update dpkg repositories and install tools
9-
109
RUN apt-get update
1110
#------------ Open JDK
1211
RUN apt-get install -y openjdk-8-jdk

nginx-reverse/reverse-proxy.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ server {
2525
proxy_pass http://nexus:8081;
2626
include /etc/nginx/conf.d/proxy-settings.conf;
2727
}
28+
29+
30+
location ^~/regweb/ {
31+
proxy_pass http://regweb:8080/regweb/;
32+
include /etc/nginx/conf.d/proxy-settings.conf;
33+
}
2834

2935
# Same like sonar.web.context=/sonar in preconfig/sonar/sonar.properties
3036
location ^~/sonar {

preconfig/docker-registry/config.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: 0.1
2+
log:
3+
fields:
4+
service: registry
5+
storage:
6+
delete:
7+
enabled: true
8+
cache:
9+
blobdescriptor: inmemory
10+
filesystem:
11+
rootdirectory: /var/lib/registry
12+
http:
13+
addr: :5000
14+
headers:
15+
X-Content-Type-Options: [nosniff]
16+
Access-Control-Allow-Origin: ['*']
17+
Access-Control-Allow-Methods: ['HEAD', 'GET', 'OPTIONS', 'DELETE']
18+
Access-Control-Allow-Headers: ['Authorization']
19+
Access-Control-Max-Age: [1728000]
20+
Access-Control-Expose-Headers: ['Docker-Content-Digest']

setupEnvironment.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ mkdir -p $USER_DATA_DIR/sonar/sonarqube_conf
7777
mkdir -p $USER_DATA_DIR/jenkins
7878
mkdir -p $USER_DATA_DIR/gitlab/config/ssl
7979
mkdir -p $USER_DATA_DIR/nexus
80+
mkdir -p $USER_DATA_DIR/docker-registry/images
8081
chown -R 200 $USER_DATA_DIR/nexus
8182
#----------------------------------
8283

@@ -127,6 +128,10 @@ fi
127128
#Copy and modify predefined Jobs and Configs
128129
cp -r preconfig/jenkins/* $USER_DATA_DIR/jenkins/
129130

131+
# Copy Registry Config
132+
cp preconfig/docker-registry/config.yml $USER_DATA_DIR/docker-registry
133+
134+
# Prepare the sample-project to run on <your-host>
130135
sed -i s#HOSTNAME#${HOSTNAME}#g spring-boot-keycloak-sample/src/main/resources/application.properties
131136
sed -i s#HOSTNAME#${HOSTNAME}#g spring-boot-keycloak-sample/src/main/resources/static/index.html
132137

@@ -148,19 +153,20 @@ echo "Environment for docker-compose.yml created"
148153
echo " "
149154
echo "use the following URL"
150155
BASE_URL="http://"$(hostname)"/"
151-
echo "Jenkins: ${BASE_URL}jenkins"
152-
echo "Nexus : ${BASE_URL}nexus"
153-
echo "Gitlab : ${BASE_URL}gitlab"
154-
echo "Sonar: ${BASE_URL}sonar (optional)"
155-
echo "Keycloak: ${BASE_URL}auth (optional)"
156+
echo "Jenkins: ${BASE_URL}jenkins"
157+
echo "Nexus : ${BASE_URL}nexus"
158+
echo "Gitlab : ${BASE_URL}gitlab"
159+
echo "Docker-Registry-Ui: ${BASE_URL}regweb"
160+
echo "Sonar: ${BASE_URL}sonar (optional)"
161+
echo "Keycloak: ${BASE_URL}auth (optional)"
156162
echo "Feel free to provide push-requests :-)"
157163
pause
158164
echo " "
159165

160166
echo "Setup finished, just type the following commands to start and see the logs of your environment"
161167
echo "docker-compose up --build -d "
162168
echo "docker-compose logs -f"
163-
169+
echo "be patient ...10 docker-containers needs time to start up "
164170

165171

166172

0 commit comments

Comments
 (0)