Merge branch 'master' into 7643-updateJenkinsAgentDockerfile

This commit is contained in:
Juan Ferrer 2024-07-15 06:42:51 +00:00
commit 4284169258
17 changed files with 152 additions and 319 deletions

View File

@ -1,47 +1,25 @@
# Docker # Verdnatura Docker images
Dockerfile and compose files used as basis for service deployment. Dockerfile and compose files used as basis for service deployment.
## Prepare environment To build, tag and push an image you can use the provided *push.sh* script.
``` ## Registry authentication
registry=[registryUrl]
image=[imageName]
tag=[versionTag]
```
## Build image Login into docker registry, if you don't logout, credentials will remain saved
in your home directory.
Build the image with *latest* tag.
```
docker build -t $registry/$image $image
```
Tag the image with version.
```
docker tag $registry/$image $registry/$image:$tag
```
Test image locally
```
docker run --name test $registry/$image:$tag
```
## Push image
Login into docker registry (If it's the first time or you are not saving credentials).
``` ```
docker login $registry docker login $registry
``` ```
Push the *latest* image and version tag. Logout from docker registry.
```
docker push $registry/$image
docker push $registry/$image:$tag
```
Logout from docker registry (If you don't logout, credentials will remain saved
in your home directory).
``` ```
docker logout $registry docker logout $registry
``` ```
## Test image
Run image locally.
```
docker run --name test $registry/$image:$tag
```

View File

@ -6,9 +6,7 @@ RUN apt-get update \
&& apt-get install -y \ && apt-get install -y \
build-essential \ build-essential \
debhelper \ debhelper \
devscripts \ devscripts
reprepro \
sudo
RUN apt-get update \ RUN apt-get update \
&& apt-get install -y --no-install-recommends \ && apt-get install -y --no-install-recommends \
@ -21,11 +19,11 @@ RUN apt-get update \
nodejs \ nodejs \
&& npm install -g npm && npm install -g npm
RUN rm -rf /var/lib/apt/lists/*
RUN groupadd -g 1000 jenkins \ RUN groupadd -g 1000 jenkins \
&& useradd -d /var/jenkins_home -u 1000 -g 1000 -m -s /bin/bash jenkins \ && useradd -d /home/jenkins -u 1000 -g 1000 -m -s /bin/bash jenkins \
&& echo "jenkins ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/jenkins \ && mkdir -p /home/jenkins/agent/workspace \
&& mkdir /reprepro && chown -R jenkins:jenkins /home/jenkins/agent
VOLUME ["/reprepro"] USER jenkins
COPY vn-includedeb /usr/bin/

View File

@ -1,35 +0,0 @@
#!/bin/bash
set -e
srcDir=.
if [ ! -f "$srcDir/debian/changelog" ]; then
echo "Invalid source directory."
exit 1
fi
codename=$1
buildDir="$srcDir/.."
if [ -z "$codename" ]; then
codename="stable"
fi
cut -d" " -f1 "$srcDir/debian/files" |
while read debFile; do
if [[ ! "$debFile" =~ .*\.deb$ ]]; then
continue
fi
echo "Adding $debFile"
cp "$buildDir/$debFile" /tmp
sudo -u www-data reprepro -b /reprepro --gnupghome /reprepro/.gnupg \
includedeb $codename "/tmp/$debFile"
done
echo "Cleaning."
(cd "$srcDir" && debian/rules clean)
rm -f $buildDir/*.deb
rm -f $buildDir/*.changes
rm -f $buildDir/*.build
rm -f $buildDir/*.buildinfo

18
image-cache.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/bash
set -e
MY_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$MY_DIR/image.conf"
image=$1
if [[ -z "$image" ]]; then
echo "Usage: $0 <image>"
exit 1
fi
taggedImage="$registry/$image"
docker image pull "$image"
docker image tag "$image" "$taggedImage"
docker image push "$taggedImage"

42
image-push.sh Executable file
View File

@ -0,0 +1,42 @@
#!/bin/bash
set -e
MY_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$MY_DIR/image.conf"
# Prepare the environment
image=$1
version=$2
revision=$3
if [[ -z "$image" || -z "$version" ]]; then
echo "Usage: $0 <image> <version> [<revision>]"
exit 1
fi
tag="$version"
if [ ! -z "$revision" ]; then
tag="$tag-$revisionPrefix$revision"
fi
fullImage="$registry/$repository/$image"
latestImage="$fullImage:latest"
taggedImage="$fullImage:$tag"
echo "Image: $taggedImage"
read -p "Continue? (Default: no) [y|n]: " ANSWER
if [ "$ANSWER" != "y" ]; then
echo "Aborting push."
exit 3
fi
# Build and tag the image
docker build -t "$latestImage" "$image"
docker tag "$latestImage" "$taggedImage"
# Push the built image
docker push "$latestImage"
docker push "$taggedImage"

3
image.conf Normal file
View File

@ -0,0 +1,3 @@
registry="registry.verdnatura.es"
repository="verdnatura"
revisionPrefix="vn"

View File

@ -31,6 +31,9 @@ RUN apt-get install -y apt-transport-https ca-certificates curl gnupg \
&& apt-get update \ && apt-get update \
&& apt-get install -y kubectl && apt-get install -y kubectl
# Docker
COPY --from=docker:26.1.3-cli /usr/local/bin/docker /usr/local/bin/
# Docker compose # Docker compose
RUN apt-get install docker-compose -y --no-install-recommends # Debian docker-compose is 1.29.2 RUN apt-get install docker-compose -y --no-install-recommends # Debian docker-compose is 1.29.2

View File

@ -1,162 +0,0 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: mrbs
labels:
app: mrbs
spec:
ingressClassName: nginx
rules:
- host: mrbs.verdnatura.es
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: mrbs
port:
number: 80
---
apiVersion: v1
kind: Service
metadata:
name: mrbs
labels:
app: mrbs
spec:
ports:
- port: 80
targetPort: 80
selector:
app: mrbs
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mrbs
labels:
app: mrbs
spec:
replicas: 1
selector:
matchLabels:
app: mrbs
strategy:
type: Recreate
template:
metadata:
labels:
app: mrbs
spec:
containers:
- image: registry.verdnatura.es/mrbs:1.11.2-vn1
name: main
ports:
- containerPort: 80
resources:
limits:
memory: 1Gi
volumeMounts:
- name: secret
mountPath: /var/www/html/web/config.inc.php
subPath: config.inc.php
restartPolicy: Always
imagePullSecrets:
- name: regcred
volumes:
- name: secret
secret:
secretName: mrbs.config
defaultMode: 420
---
apiVersion: v1
kind: Service
metadata:
name: mrbs-db
labels:
app: mrbs-db
spec:
type: NodePort
ports:
- port: 3306
targetPort: 3306
selector:
io.kompose.service: mrbs-db
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mrbs.db
labels:
app: mrbs
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: mrbs-db
strategy:
type: Recreate
template:
metadata:
labels:
io.kompose.service: mrbs-db
spec:
containers:
- image: mariadb:10.11.4
name: mrbs-db
args:
- --transaction-isolation=READ-COMMITTED
- --binlog-format=ROW
- --ignore-db-dir=lost+found
env:
- name: MYSQL_DATABASE
value: mrbs
- name: MYSQL_USER
value: mrbs
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: mrbs.env
key: MYSQL_PASSWORD
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mrbs.env
key: MYSQL_ROOT_PASSWORD
ports:
- containerPort: 3306
resources:
limits:
memory: 500Mi
volumeMounts:
- mountPath: /var/lib/mysql
name: db
- mountPath: /etc/localtime
name: localtime
readOnly: true
restartPolicy: Always
volumes:
- name: db
persistentVolumeClaim:
claimName: mrbs.db
- name: localtime
hostPath:
path: /etc/localtime
type: File
readOnly: true
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mrbs.db
labels:
app: mrdb
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
storageClassName: csi-rbd-ssd-sc
volumeMode: Filesystem

View File

@ -11,9 +11,9 @@ RUN echo "deb http://ftp.es.debian.org/debian stretch-backports main" \
php-xml \ php-xml \
&& rm -rf /var/lib/apt/lists/* \ && rm -rf /var/lib/apt/lists/* \
&& . /etc/apache2/envvars \ && . /etc/apache2/envvars \
&& ln -sfT /dev/stderr "$APACHE_LOG_DIR/error.log" \ && ln -sfT /dev/stderr "$APACHE_LOG_DIR/error.log" \
&& ln -sfT /dev/stdout "$APACHE_LOG_DIR/access.log" \ && ln -sfT /dev/stdout "$APACHE_LOG_DIR/access.log" \
&& ln -sfT /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log" && ln -sfT /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log"
COPY apache.conf /etc/apache2/sites-available/phpldapadmin.conf COPY apache.conf /etc/apache2/sites-available/phpldapadmin.conf

View File

@ -1,44 +0,0 @@
version: '3.2'
services:
agent:
image: portainer/agent:2.17.1
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /var/lib/docker/volumes:/var/lib/docker/volumes
- /var/lib/rexray/volumes:/var/lib/rexray/volumes
networks:
- agent
deploy:
mode: global
placement:
constraints: [node.platform.os == linux]
resources:
limits:
memory: 500M
main:
image: portainer/portainer-ce:2.17.1
command: -H tcp://tasks.agent:9001 --tlsskipverify
ports:
- "80:9000"
- "8000:8000"
volumes:
- data:/data
networks:
- agent
deploy:
mode: replicated
replicas: 1
placement:
constraints: [node.role == manager]
resources:
limits:
memory: 2G
networks:
agent:
driver: overlay
attachable: true
volumes:
data:
driver: rexray
driver_opts:
size: 4

View File

@ -1,7 +1,31 @@
FROM php:7.4.1-apache FROM debian:bookworm-slim
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update \ RUN apt-get update \
&& apt-get install -y --no-install-recommends reprepro \ && apt-get install -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* apache2 \
reprepro \
openssh-server \
&& rm -rf /var/lib/apt/lists/* \
&& . /etc/apache2/envvars \
&& ln -sfT /dev/stderr "$APACHE_LOG_DIR/error.log" \
&& ln -sfT /dev/stdout "$APACHE_LOG_DIR/access.log" \
&& ln -sfT /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log"
COPY apache.conf /etc/apache2/conf-enabled/reprepro.conf WORKDIR /var/lib/reprepro
EXPOSE 80
RUN groupadd -g 600 reprepro \
&& useradd -d /var/lib/reprepro -u 600 -g 600 -m -s /bin/bash reprepro
COPY apache-conf.conf /etc/apache2/conf-available/reprepro.conf
COPY apache-site.conf /etc/apache2/sites-available/reprepro.conf
RUN a2enconf reprepro \
&& a2ensite reprepro \
&& a2dissite 000-default
COPY entrypoint.sh /
ENTRYPOINT [ "/entrypoint.sh" ]
CMD ["apachectl", "-D", "FOREGROUND"]

7
reprepro/README.md Normal file
View File

@ -0,0 +1,7 @@
# Reprepro docker image
APT server using Reprepro and Apache HTTP server.
## Links
* https://github.com/bbinet/docker-reprepro

View File

@ -0,0 +1,8 @@
<Directory /var/lib/reprepro/repo>
Options Indexes
Options +FollowSymLinks
AllowOverride None
Order Allow,Deny
Allow From All
Require all granted
</Directory>

View File

@ -0,0 +1,3 @@
<VirtualHost *:80>
DocumentRoot /var/lib/reprepro/repo/
</VirtualHost>

View File

@ -1,13 +0,0 @@
<Directory /var/www/html>
Options Indexes
Options +FollowSymLinks
AllowOverride None
Order Allow,Deny
Allow From All
Require all granted
</Directory>
<Directory /var/www/html/.gnupg>
Order Deny,Allow
Deny From All
Require all denied
</Directory>

4
reprepro/entrypoint.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
service ssh start
exec $@

View File

@ -10,22 +10,21 @@ RUN pip install --upgrade pip \
pip install --upgrade pywinrm[credssp] pip install --upgrade pywinrm[credssp]
#RUN apt-get update \ #RUN apt-get update \
# && apt-get upgrade -y \ # && apt-get upgrade -y \
# && apt-get install -y --no-install-recommends \ # && apt-get install -y --no-install-recommends \
# gcc \ # gcc \
# libffi-devel \ # libffi-devel \
# python3 \ # python3 \
# epel-release \ # epel-release \
# python3-pip \ # python3-pip \
# wget # wget
#RUN pip3 install --upgrade pip \ #RUN pip3 install --upgrade pip \
# pip3 install --upgrade virtualenv \ # pip3 install --upgrade virtualenv \
# pip3 install pywinrm[kerberos] \ # pip3 install pywinrm[kerberos] \
# pip3 install pywinrm \ # pip3 install pywinrm \
# pip3 install jmspath \ # pip3 install jmspath \
# pip3 install request prueba # pip3 install request prueba
RUN ls /usr/local/bin/ RUN ls /usr/local/bin/