diff --git a/PRA05_ANSWER/.gitignore b/PRA05_ANSWER/.gitignore new file mode 100644 index 00000000..0615faca --- /dev/null +++ b/PRA05_ANSWER/.gitignore @@ -0,0 +1,2 @@ +/jenkins_home/ +/jar/ \ No newline at end of file diff --git a/PRA05_ANSWER/_PRA/PRA01-pull-request.md b/PRA05_ANSWER/_PRA/PRA01-pull-request.md new file mode 100644 index 00000000..c3ed864a --- /dev/null +++ b/PRA05_ANSWER/_PRA/PRA01-pull-request.md @@ -0,0 +1,17 @@ +# PRA01 + +Published on [https://jc-programs.github.io/quarto-prueba/](https://jc-programs.github.io/quarto-prueba/) + +## Tasks + +1. [x] Create a Local Markdown Quarto Website +2. [x] Modify the Website + - [x] Add Call-outs + - [x] Create New Pages + - [x] Basic Formatting and Layout +3. [x] Implement Website Navigation +4. [x] Include Mermaid Diagrams +5. [x] Configure the `_quarto.yml` File +6. [x] Set Up a Git Repository and Link to GitHub +7. [x] Publish the Website to GitHub Pages + [https://jc-programs.github.io/quarto-prueba/](https://jc-programs.github.io/quarto-prueba/) \ No newline at end of file diff --git a/PRA05_ANSWER/_PRA/PRA02-pull-request.md b/PRA05_ANSWER/_PRA/PRA02-pull-request.md new file mode 100644 index 00000000..bff763ce --- /dev/null +++ b/PRA05_ANSWER/_PRA/PRA02-pull-request.md @@ -0,0 +1,45 @@ +# PRA02 + +Published on [https://jc-programs.github.io/quarto-prueba/](https://jc-programs.github.io/quarto-prueba/) + +![Queued job](img/01-queued.png) + +![Running job](img/02-running.png) + +![Published](img/03-published.png) + + +```{.yml filename=".github/workflows/publish.yml"} +name: Quarto Publish + +on: + push: + branches: + - master + workflow_dispatch: + +jobs: + build-deploy: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Quarto + uses: quarto-dev/quarto-actions/setup@v2 + + - name: Render and Publish + uses: quarto-dev/quarto-actions/publish@v2 + with: + target: gh-pages + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +``` + + +## Tasks + +1. [x] Complete a Local Publish +2. [x] Create a `publish.yml` GitHub Action diff --git a/PRA05_ANSWER/_PRA/PRA03-pull-request.md b/PRA05_ANSWER/_PRA/PRA03-pull-request.md new file mode 100644 index 00000000..4cada3f9 --- /dev/null +++ b/PRA05_ANSWER/_PRA/PRA03-pull-request.md @@ -0,0 +1,213 @@ +# PRA03 + +## Explanation + +I deleted `.github/workflows/publish.yml` to avoid publication with github actions. + +Script execution : +1. Creation of log directory if not exists. +1. Definition of log functions: + - log_message with 2 arguments: + 1. kind of message + 2. message + - log_message_error. Only message argument + - log_message_ok. Only message argument +1. Definition of `count` var to enumerate executions. This var will be stored in a file to get his value in next executions +1. Check if there is a commit message and if it is the only argument +1. Log the commit message +1. Store in a var the current git branch +1. Check if we are in a git repository +1. Check if there is something to commit. If not log it and exit +1. Execute and log `git add` +1. Execute and log `git commmit` +1. Execute and log `git push` +1. Execute and log `quarto publish gh-pages --no-prompt` + +## Execution example + +![Execution example](img/01-pra3-run.png) + +## Contents of `publish_quarto.sh` +```{.sh filename="publish_quarto.sh"} +#!/bin/bash + +LOG_DIR=logs + +# check if log directory exists +if [ ! -d "${LOG_DIR}" ]; then + # if not then we try to create it + mkdir "${LOG_DIR}" + if [ $? -ne 0 ] ; then + echo "log directory '${LOG_DIR}' does not exist and can't be created." + exit 1 + fi +fi + +log_message() { + local count=$(printf "%02d" ${COUNT}) + local type="$1" + local message="$2" + local timestamp=$(date +"%H:%M:%S") + echo "${count}-[${timestamp}] ${type}: ${message}" | tee -a "${LOG_FILE}" +} + +log_message_error() { + log_message "ERROR" "$1" +} + +log_message_ok() { + log_message "OK" "$1" +} + +LOG_FILE=${LOG_DIR}/$(date +"%Y-%m-%d").log +COUNT_FILE=${LOG_DIR}/count + +# using a count for better track of different executions +# if log file don't exists => first execution +if [ ! -f "${LOG_FILE}" ]; then + COUNT=0 + # reset count => Delete count file. No error if not exists + rm -f -- $COUNT_FILE +else + # read last value + read COUNT < $COUNT_FILE 2>/dev/null + # count file must exists because is not the first execution + if [ $? -ne 0 ]; then + COUNT=99 + log_message_error "Can't read count file '$COUNT_FILE'" + exit 1 + fi +fi +# increment count by 1 +(( COUNT++ )) +# write count to count file +echo "$COUNT" > $COUNT_FILE +if [ $? -ne 0 ]; then + log_message_error "Can't write count to count file '$COUNT_FILE'" + exit 1 +fi + +# separating executions in log file with an empty line +if [ "$COUNT" -gt 1 ]; then + echo >> "${LOG_FILE}" +fi + +# Check if the commit message is provided +if [ -z "$1" ]; then + log_message_error "Please provide a commit message." + exit 1 +fi + +# Check if the commit message is the only argument +if [ $# -gt 1 ]; then + log_message_error "The only admited argument is the commit message." + log_message_error "If the message is more than a word enclose it with double quotes: \"" + log_message_error "Arguments where '$*'" + exit 1 +fi + +# log commit message +log_message "COMMIT MESSAGE" "$1" + +# get current branch +BRANCH=$(git branch --show-current 2>/dev/null) +if [ $? -ne 0 ]; then + log_message_error "git branch --show-current" + exit 1 +fi + +# Check if there are some changes to save +# https://stackoverflow.com/questions/3878624/how-do-i-programmatically-determine-if-there-are-uncommitted-changes +GS=$(git status --porcelain=v1 2>/dev/null) +if [ $? -eq 128 ]; then + log_message_error "There is no git repository in current folder." + log_message_error "Current folder is: $(pwd)" + exit 1 +fi + +if [ -z "${GS}" ]; then + log_message "INFO" "There are no changes to commit." + exit 0 +fi + +git add . 2>/dev/null +if [ $? -ne 0 ]; then + log_message_error "git add ." + exit 1 +else + log_message_ok "git add ." +fi + +git commit -m "$1" 2>/dev/null +if [ $? -ne 0 ]; then + log_message_error "git commit -m \"$1\"" + exit 1 +else + log_message_ok "git commit -m \"$1\"" +fi + +git push origin $BRANCH 2>/dev/null +if [ $? -ne 0 ]; then + log_message_error "git push origin $BRANCH" + exit 1 +else + log_message_ok "git push origin $BRANCH" +fi + +quarto publish gh-pages --no-prompt 2>/dev/null +if [ $? -ne 0 ]; then + log_message_error "quarto publish gh-pages --no-prompt" + exit 1 +else + log_message_ok "quarto publish gh-pages --no-prompt" +fi + +exit 0 +``` + + +## Contents of `logs/2024-11-28.log` + +```{.log filename="logs/2024-11-28.log"} +01-[11:33:59] COMMIT MESSAGE: Changed something to test publish_quarto.sh +01-[11:33:59] OK: git add . +01-[11:33:59] OK: git commit -m "Changed something to test publish_quarto.sh" +01-[11:34:00] OK: git push origin master +01-[11:34:08] OK: quarto publish gh-pages --no-prompt + +02-[11:37:11] COMMIT MESSAGE: Changed something more in about.qmd to test publish_quarto.sh +02-[11:37:11] OK: git add . +02-[11:37:11] OK: git commit -m "Changed something more in about.qmd to test publish_quarto.sh" +02-[11:37:12] OK: git push origin master +02-[11:37:19] OK: quarto publish gh-pages --no-prompt + +03-[11:43:38] COMMIT MESSAGE: permission to execute publish_quarto.sh +03-[11:43:38] OK: git add . +03-[11:43:38] OK: git commit -m "permission to execute publish_quarto.sh" +03-[11:43:39] OK: git push origin master +03-[11:43:46] OK: quarto publish gh-pages --no-prompt + +04-[12:03:12] COMMIT MESSAGE: correct publish_quarto.sh +04-[12:03:12] OK: git add . +04-[12:03:12] OK: git commit -m "correct publish_quarto.sh" +04-[12:03:14] OK: git push origin master +04-[12:03:20] OK: quarto publish gh-pages --no-prompt + +05-[12:03:58] COMMIT MESSAGE: check what happens if there is nothing to commit +05-[12:03:58] INFO: There are no changes to commit. + +06-[12:06:16] COMMIT MESSAGE: mv .git .git.bak to check error when there is no repo +06-[12:06:16] ERROR: git branch --show-current + +07-[12:07:05] COMMIT MESSAGE: mv .git.bak .git to check info when there is repo but no changes +07-[12:07:05] INFO: There are no changes to commit. +``` + + +## Tasks + +1. [x] Create the Bash Script +2. [x] Add logging output +3. [x] Make the Script Executable +4. [x] Use the Script + diff --git a/PRA05_ANSWER/_PRA/PRA04-pull-request.md b/PRA05_ANSWER/_PRA/PRA04-pull-request.md new file mode 100644 index 00000000..4e7ea1a4 --- /dev/null +++ b/PRA05_ANSWER/_PRA/PRA04-pull-request.md @@ -0,0 +1,75 @@ +# PRA04 + +## Explanation + +I created scripts to automate all the process using .env variables to: +- prepare resources to create both dockers: `copy-resources-sh` + - backend + - frontend +- create backend and frontend dockers: `docker-build.sh` + Replaced `openjdk:21-jdk-slim` by `bellsoft/liberica-openjdk-alpine:21` because is lighter and is the official recomendation from [spring.io](https://spring.io/quickstart) +- create `docker-run.sh` to execute both dockers + +To load variables from .env file I created some util files: +- remove-comments.sed + remove all shell comments, after # char, but keeping strings. Code based on [this post](https://sleeplessbeastie.eu/2012/11/07/how-to-remove-comments-from-a-shell-script/) + + Example cleaning of comments and empty lines: + ``` + bash util/clean-env-file.sh util/to-test.sh + ``` + + Example of loading env vars: + ``` + bash util/test-load-env.sh + ``` + +I created also `compose.yaml` that uses both docker images created before. +To use `docker compose`: + + ``` + docker compose up + + # if detached is needed: + docker compose up -d + # and then to kill dockers: + docker kill pra04_answer-backend-1 + docker kill pra04_answer-frontend-1 + ``` + + + +## Screenshots + +### docker build backend +![docker build backend](img/pra04/01-build-backend.png) + +### docker build frontend +![docker build frontend](img/pra04/02-build-frontend.png) + +### list docker images +![list docker images](img/pra04/02--docker-images.png) + +### launching dockers +![launching dockers](img/pra04/03-launch-dockers.png) + +### dockers working +![dockers working](img/pra04/04-web-working.png) + +### killing dockers +![killing dockers](img/pra04/05-killing-dockers.png) + +### running docker compose +![docker compose running](img/pra04/06-docker-compose-running.png) + + +## Tasks + +1. [x] Install Docker CLI +2. [x] Create a DockerHub Account +3. [x] Create Dockerfiles +4. [x] Build and Run Docker Containers +5. [ ] H2 Database Configuration +6. [ ] Implement Book API with Spring Boot +7. [x] Consume API with React using Axios +8. [x] docker compose diff --git a/PRA05_ANSWER/_PRA/PRA05-pull-request.md b/PRA05_ANSWER/_PRA/PRA05-pull-request.md new file mode 100644 index 00000000..d9c95ad8 --- /dev/null +++ b/PRA05_ANSWER/_PRA/PRA05-pull-request.md @@ -0,0 +1,364 @@ +# PRA05 + +## Tasks + +1. [x] Pull Jenkins Docker Image +2. [x] Build and Run Jenkins Container +3. [x] Configure Jenkins Account +4. [x] Install Basic Plugins + - [x] Maven Integration + - [x] Git + - [x] Docker + - [x] SSH + - [x] SonarQube Scanner +5. [x] Create a Pipeline for Spring Boot Project +6. [x] Bonus: Export & import container + +## Execution + +Primero: descargar de hub.docker.com jenkins +``` +# descargar de hub.docker.com jenkins +docker pull jenkins/jenkins +``` + + +creado script `create-run-jenkins.sh` +``` +#!/bin/bash + +# name of Jenkins container +NAME=jenkins + +# save current dir +DIR=$(pwd) + +if [ $( docker ps -a -f name="${NAME}" 2> /dev/null | wc -l ) -eq 2 ]; then + echo "${NAME} container already exists" +else + # script dir is the location of this script + SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + # jenkins home is in this same folder + DIR_HOME="${SCRIPT_DIR}"/jenkins_home + docker run -d -p 9090:8080 -p 50000:50000 \ + -v "${DIR_HOME}":/var/jenkins_home \ + -v /var/run/docker.sock:/var/run/docker.sock \ + --privileged \ + --name "${NAME}" \ + jenkins/jenkins:latest + echo "${NAME} created and running" + echo "Jenkins home directory is: ${DIR_HOME}" +fi + +if [ "$(docker inspect -f '{{.State.Status}}' "${NAME}" 2>/dev/null)" = "running" ]; then + echo "${NAME} container is already running" +else + docker start "${NAME}" + echo "${NAME} container started" +fi + +# go to saved location +cd "${DIR}" +``` + + +``` +bash create-run-jenkins.sh + +# obtener el password que hay que introducir con +docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword +``` + +abrir el navegador en esta [ulr de login](http://localhost:9090/login) e introducir el password obtenido con la instrucción anterior. + +Ya desde la [web de administración de Jenkins](http://localhost:9090/): +- Instalar los plugins sugeridos +- Configurar el usuarios de administrado +- Tools + - Maven 3.9.9, con autoinstalador + - JDK's: + Con autoinstalador desde url y en el directorio JDK**x** + - [JDK8](https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/tag/jdk8u292-b10) en el directorio `jdk8u292-b10` + - [JDK11](https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz) en el directorio `jdk-11.0.2` + - [JDK17](https://download.java.net/java/GA/jdk17.0.2/dfd4a8d0985749f896bed50d7138ee7f/8/GPL/openjdk-17.0.2_linux-x64_bin.tar.gz) en el directorio `jdk-17.0.2` + - [JDK21](https://download.java.net/java/GA/jdk21.0.2/f2283984656d49d69e91c558476027ac/13/GPL/openjdk-21.0.2_linux-x64_bin.tar.gz) en el directorio `jdk-21.0.2` + + +Probada app Vaadin para hacer las pruebas de pipeline +su [github](https://github.com/jc-programs/SpringConference.git). Se utilizará la branch `docker-version` +``` +mvn clean install -Pproduction +java -jar target/springConference-0.0.1-SNAPSHOT.jar +# abrir el navegador en http://localhost:8080 +``` + +groovy con mi pipeline +``` +pipeline { + agent any + + environment { + // DOCKERHUB_CREDENTIALS = credentials('dockerhub_id') + IMAGE_NAME = 'jcprograms/springconference' + IMAGE_TAG = "${BUILD_NUMBER}" + } + + tools { + maven "MAVEN3" + jdk 'JDK17' + } + + stages { + stage ('Checking java version') { + steps { + sh 'java --version' + } + } + + stage ('Checking maven version') { + steps { + sh 'mvn --version' + } + } + + stage ('Checking docker version') { + steps { + sh 'docker --version' + } + } + + + stage('Checkout git') { + steps { + // set repository url and branch + git branch: 'docker-version', url: 'https://github.com/jc-programs/SpringConference.git' + } + } + + stage ('build app skiping test') { + steps { + sh 'mvn clean package -DskipTests=true -Pproduction' + } + } + + stage('Archive .jar') { + steps { + archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true + } + } + + stage('Build Docker Image') { + steps { + script { + docker.build("${IMAGE_NAME}:${IMAGE_TAG}") + } + } + } + + + stage('Login to Docker Hub') { + steps { + script { + docker.withRegistry('', 'dockerhub_id') { + // This block will log in using the credentials specified + sh 'echo loged in docker' + } + } + } + } + + stage('Push Image to Docker Hub') { + steps { + script { + docker.withRegistry('', 'dockerhub_id') { + docker.image("${IMAGE_NAME}:${IMAGE_TAG}").push() + docker.image("${IMAGE_NAME}:${IMAGE_TAG}").push('latest') + } + } + } + } + } + + post { + always { + sh "docker rmi ${IMAGE_NAME}:${IMAGE_TAG}" + sh "docker rmi ${IMAGE_NAME}:latest" + } + } +}``` + +## Creando la imagen docker con el compilado + +Añado en el directorio raíz del proyecto java el fichero `Dockerfile` + +```{Dockerfile} +FROM bellsoft/liberica-openjdk-alpine:17 +ARG JAR_FILE=target/*.jar +COPY ${JAR_FILE} app.jar +EXPOSE 8080 +ENTRYPOINT ["java","-jar","/app.jar"] +``` + +## instalación de docker en el container de jenkins + +con el container de jenkins ejecutándose conectarse a su `bash` como root +``` +docker exec -it -u root jenkins bash +``` + +y dentro de instalar docker con +``` +apt install docker.io +``` +y comprobar que los permisos del socket de docker son los correctos +``` +ls -la /var/run/docker.sock +``` +debe devolver +``` +srw-rw---- 1 root jenkins 0 Dec 10 07:41 /var/run/docker.sock +``` +si el socket no tiene estos permisos cambiarlos con: +``` +chown root:jenkins /var/run/docker.sock +chmod 660 /var/run/docker.sock +``` + + + + +## Extra: export & import docker container + +Siguiendo las instrucciones de este [artículo](https://www.maketecheasier.com/copy-move-docker-container-to-another-host/) he conseguido exportar e importar el contenido de un contenedor docker. + +### Paso 0: instalar `docker-volumes.sh` + +[github de `docker-volumes.sh`](https://github.com/ricardobranco777/docker-volumes.sh) + + +https://raw.githubusercontent.com/ricardobranco777/docker-volumes.sh/master/docker-volumes.sh + +``` +curl -o docker-volumes.sh https://raw.githubusercontent.com/ricardobranco777/docker-volumes.sh/master/docker-volumes.sh +chmod +x docker-volumes.sh +sudo mv docker-volumes.sh /usr/local/bin/ + +``` + +### Paso 1: exportar docker contaniner + +mi container se llama `jenkins` +docker image se llamará `jenkins-image` y se guardará en `jenkins.tar` +el volumen (jenkins_home) se guarda en el fichero `jenkins-volume.tar` + +``` +# parar el container +docker stop jenkins + +# guardar imagen del container en jenkins-image +docker commit jenkins jenkins-image + +# guardar los datos de la imagen en fichero .tar +docker save -o jenkins.tar jenkins-image + +# guardar el volumen del contenedor +docker-volumes.sh jenkins save jenkins-volume.tar +``` + + +### Paso 2. Importar la imagen sin importar el volumen + +Log in to your remote host, then run the following command to load it to your remote machine’s Docker daemon: + +``` +docker load -i ./jenkins.tar +``` + +se crea la imagen `jenkins-image` +pero la vamos a renombrar a `pra05/jenkins-image` + +``` +docker image tag jenkins-image:latest pra05/jenkins-image:latest +docker rmi jenkins-image +``` + + +Use docker create to reinitialize your Docker container image with its original run flags from your source machine. For instance, my Nginx Docker container originally had port 80 mapped to my host machine’s port 8080: + +``` +docker create --name jenkins-home -p 9090:8080 -p 50000:50000 pra05/jenkins-image +``` + +Run your newly imported Docker container: + +``` +docker start jenkins-home +``` + +Confirm that your imported image is working properly by listing all the active containers in the system: + +``` +docker ps +``` + + +#### Paso 3. Importar la imagen importando el volumen +Create a new Docker container using your exported image file: + +``` +docker create --name jenkins-home \ + -v jenkins_home:/var/jenkins_home \ + -p 9090:8080 -p 50000:50000 pra05/jenkins-image +``` + +Run the docker-volume.sh script with your original .tar file to load it to your new system’s Docker daemon: + +``` +docker-volumes.sh jenkins-home load jenkins-volume.tar +``` + +Start your new Docker container by running the following command: + +``` +docker start jenkins-home +``` + +Test if your container is loading your volume properly by looking at its internal config data: + +``` +docker inspect -f '{{ .Mounts }}' jenkins-home +``` + + +## Screenshots + +### configuración maven3 +01. ![configuración maven3](img/pra05/jenkins/01-maven3.png) +### configuración jdk8 +02. ![configuración jdk8](img/pra05/jenkins/02-jdk8.png) +### configuración jdk11 +03. ![configuración jdk11](img/pra05/jenkins/03-jdk11.png) +### configuración jdk17 +04. ![configuración jdk17](img/pra05/jenkins/04-jdk17.png) +### configuración jdk21 +05. ![configuración jdk21](img/pra05/jenkins/05-jdk21.png) +### configuración maven-integration +06. ![configuración maven-integration](img/pra05/jenkins/06-maven-integration.png) +### configuración docker-plugins +07. ![configuración docker-plugins](img/pra05/jenkins/07-docker-plugins.png) +### configuración ssh-plugins +08. ![configuración ssh-plugins](img/pra05/jenkins/08-ssh-plugins.png) +### configuración sonnar-qube-plugin +09. ![configuración sonnar-qube-plugin](img/pra05/jenkins/09-sonnar-qube-plugin.png) +### pipeline sin docker +10. ![pipeline sin docker](img/pra05/jenkins/10-pipeline-without-docker.png) +### pipeline con docker y dockerhub +11. ![pipeline con docker y dockerhub](img/pra05/jenkins/11-pipeline-with-docker-and-dockerhub.png) +### pipeline con docker y dockerhub +12. ![pipeline con docker y dockerhub](img/pra05/jenkins/12-pipeline-with-docker-and-dockerhub.png) +### probando la imagen de docker: login y pull +13. ![probando la imagen de docker: login y pull](img/pra05/jenkins/13-testing-my-docker-image-login-pull.png) +### probando la imagen de docker: running +14. ![probando la imagen de docker: running](img/pra05/jenkins/14-testing-my-docker-running.png) +### probando la imagen de docker: funciona! +15. ![probando la imagen de docker: funciona!](img/pra05/jenkins/15-testing-my-docker-is-working.png) diff --git a/PRA05_ANSWER/_PRA/img/01-pra3-run.png b/PRA05_ANSWER/_PRA/img/01-pra3-run.png new file mode 100644 index 00000000..47f3039b Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/01-pra3-run.png differ diff --git a/PRA05_ANSWER/_PRA/img/01-queued.png b/PRA05_ANSWER/_PRA/img/01-queued.png new file mode 100644 index 00000000..8d8a45e9 Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/01-queued.png differ diff --git a/PRA05_ANSWER/_PRA/img/02-running.png b/PRA05_ANSWER/_PRA/img/02-running.png new file mode 100644 index 00000000..a9edf4b3 Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/02-running.png differ diff --git a/PRA05_ANSWER/_PRA/img/03-published.png b/PRA05_ANSWER/_PRA/img/03-published.png new file mode 100644 index 00000000..aae4df04 Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/03-published.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra04/01-build-backend.png b/PRA05_ANSWER/_PRA/img/pra04/01-build-backend.png new file mode 100644 index 00000000..d4aafe4e Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra04/01-build-backend.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra04/02--docker-images.png b/PRA05_ANSWER/_PRA/img/pra04/02--docker-images.png new file mode 100644 index 00000000..9927d431 Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra04/02--docker-images.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra04/02-build-frontend.png b/PRA05_ANSWER/_PRA/img/pra04/02-build-frontend.png new file mode 100644 index 00000000..fd132ded Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra04/02-build-frontend.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra04/03-launch-dockers.png b/PRA05_ANSWER/_PRA/img/pra04/03-launch-dockers.png new file mode 100644 index 00000000..21fc6fe9 Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra04/03-launch-dockers.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra04/04-web-working.png b/PRA05_ANSWER/_PRA/img/pra04/04-web-working.png new file mode 100644 index 00000000..21e141cb Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra04/04-web-working.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra04/05-killing-dockers.png b/PRA05_ANSWER/_PRA/img/pra04/05-killing-dockers.png new file mode 100644 index 00000000..2c1db068 Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra04/05-killing-dockers.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra04/06-docker-compose-running.png b/PRA05_ANSWER/_PRA/img/pra04/06-docker-compose-running.png new file mode 100644 index 00000000..11646645 Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra04/06-docker-compose-running.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra05/01-download-jenkins-cli.png b/PRA05_ANSWER/_PRA/img/pra05/01-download-jenkins-cli.png new file mode 100644 index 00000000..a41dc787 Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra05/01-download-jenkins-cli.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra05/02-install-docker-jenkins-cli.png b/PRA05_ANSWER/_PRA/img/pra05/02-install-docker-jenkins-cli.png new file mode 100644 index 00000000..3c8d450d Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra05/02-install-docker-jenkins-cli.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra05/jenkins/01-maven3.png b/PRA05_ANSWER/_PRA/img/pra05/jenkins/01-maven3.png new file mode 100644 index 00000000..b24f0bbe Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra05/jenkins/01-maven3.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra05/jenkins/02-jdk8.png b/PRA05_ANSWER/_PRA/img/pra05/jenkins/02-jdk8.png new file mode 100644 index 00000000..cb15845f Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra05/jenkins/02-jdk8.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra05/jenkins/03-jdk11.png b/PRA05_ANSWER/_PRA/img/pra05/jenkins/03-jdk11.png new file mode 100644 index 00000000..2f31409b Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra05/jenkins/03-jdk11.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra05/jenkins/04-jdk17.png b/PRA05_ANSWER/_PRA/img/pra05/jenkins/04-jdk17.png new file mode 100644 index 00000000..6a26fa98 Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra05/jenkins/04-jdk17.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra05/jenkins/05-jdk21.png b/PRA05_ANSWER/_PRA/img/pra05/jenkins/05-jdk21.png new file mode 100644 index 00000000..42693f19 Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra05/jenkins/05-jdk21.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra05/jenkins/06-maven-integration.png b/PRA05_ANSWER/_PRA/img/pra05/jenkins/06-maven-integration.png new file mode 100644 index 00000000..a01149d4 Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra05/jenkins/06-maven-integration.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra05/jenkins/07-docker-plugins.png b/PRA05_ANSWER/_PRA/img/pra05/jenkins/07-docker-plugins.png new file mode 100644 index 00000000..1d3b07ab Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra05/jenkins/07-docker-plugins.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra05/jenkins/08-ssh-plugins.png b/PRA05_ANSWER/_PRA/img/pra05/jenkins/08-ssh-plugins.png new file mode 100644 index 00000000..209131e7 Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra05/jenkins/08-ssh-plugins.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra05/jenkins/09-sonnar-qube-plugin.png b/PRA05_ANSWER/_PRA/img/pra05/jenkins/09-sonnar-qube-plugin.png new file mode 100644 index 00000000..dff82b06 Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra05/jenkins/09-sonnar-qube-plugin.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra05/jenkins/10-pipeline-without-docker.png b/PRA05_ANSWER/_PRA/img/pra05/jenkins/10-pipeline-without-docker.png new file mode 100644 index 00000000..de1c1a56 Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra05/jenkins/10-pipeline-without-docker.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra05/jenkins/11-pipeline-with-docker-and-dockerhub.png b/PRA05_ANSWER/_PRA/img/pra05/jenkins/11-pipeline-with-docker-and-dockerhub.png new file mode 100644 index 00000000..f749dd80 Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra05/jenkins/11-pipeline-with-docker-and-dockerhub.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra05/jenkins/12-pipeline-with-docker-and-dockerhub.png b/PRA05_ANSWER/_PRA/img/pra05/jenkins/12-pipeline-with-docker-and-dockerhub.png new file mode 100644 index 00000000..17d87c51 Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra05/jenkins/12-pipeline-with-docker-and-dockerhub.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra05/jenkins/13-testing-my-docker-image-login-pull.png b/PRA05_ANSWER/_PRA/img/pra05/jenkins/13-testing-my-docker-image-login-pull.png new file mode 100644 index 00000000..3bcb7cdc Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra05/jenkins/13-testing-my-docker-image-login-pull.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra05/jenkins/14-testing-my-docker-running.png b/PRA05_ANSWER/_PRA/img/pra05/jenkins/14-testing-my-docker-running.png new file mode 100644 index 00000000..f93f058c Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra05/jenkins/14-testing-my-docker-running.png differ diff --git a/PRA05_ANSWER/_PRA/img/pra05/jenkins/15-testing-my-docker-is-working.png b/PRA05_ANSWER/_PRA/img/pra05/jenkins/15-testing-my-docker-is-working.png new file mode 100644 index 00000000..6d307c17 Binary files /dev/null and b/PRA05_ANSWER/_PRA/img/pra05/jenkins/15-testing-my-docker-is-working.png differ diff --git a/PRA05_ANSWER/_PRA/import-container.md b/PRA05_ANSWER/_PRA/import-container.md new file mode 100644 index 00000000..c0e6890b --- /dev/null +++ b/PRA05_ANSWER/_PRA/import-container.md @@ -0,0 +1,62 @@ +# Paso 1 + +Log in to your remote host, then run the following command to load it to your remote machine’s Docker daemon: + +``` +docker load -i ./jenkins.tar +``` + +se crea la imagen `jenkins-image` +pero la vamos a renombrar a `pra05/jenkins-image` + +``` +docker image tag jenkins-image:latest pra05/jenkins-image:latest +docker rmi jenkins-image +``` + + +Use docker create to reinitialize your Docker container image with its original run flags from your source machine. For instance, my Nginx Docker container originally had port 80 mapped to my host machine’s port 8080: + +``` +docker create --name jenkins-home -p 9090:8080 -p 50000:50000 pra05/jenkins-image +``` + +Run your newly imported Docker container: + +``` +docker start jenkins-home +``` + +Confirm that your imported image is working properly by listing all the active containers in the system: + +``` +docker ps +``` + + +# Paso 2 +Create a new Docker container using your exported image file: + +``` +docker create --name jenkins-home \ + -v jenkins_home:/var/jenkins_home \ + -p 9090:8080 -p 50000:50000 pra05/jenkins-image +``` + +Run the docker-volume.sh script with your original .tar file to load it to your new system’s Docker daemon: + +``` +docker-volumes.sh jenkins-home load jenkins-volume.tar +``` + +Start your new Docker container by running the following command: + +``` +docker start jenkins-home +``` + +Test if your container is loading your volume properly by looking at its internal config data: + +``` +docker inspect -f '{{ .Mounts }}' jenkins-home +``` diff --git a/PRA05_ANSWER/create-run-jenkins.sh b/PRA05_ANSWER/create-run-jenkins.sh new file mode 100644 index 00000000..b32912bf --- /dev/null +++ b/PRA05_ANSWER/create-run-jenkins.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# name of Jenkins container +NAME=jenkins + +# save current dir +DIR=$(pwd) + +if [ $( docker ps -a -f name="${NAME}" 2> /dev/null | wc -l ) -eq 2 ]; then + echo "${NAME} container already exists" +else + # script dir is the location of this script + SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + # jenkins home is in this same folder + DIR_HOME="${SCRIPT_DIR}"/jenkins_home + docker run -d -p 9090:8080 -p 50000:50000 \ + -v "${DIR_HOME}":/var/jenkins_home \ + -v /var/run/docker.sock:/var/run/docker.sock \ + --privileged \ + --name "${NAME}" \ + jenkins/jenkins:latest + echo "${NAME} created and running" + echo "Jenkins home directory is: ${DIR_HOME}" +fi + +if [ "$(docker inspect -f '{{.State.Status}}' "${NAME}" 2>/dev/null)" = "running" ]; then + echo "${NAME} container is already running" +else + docker start "${NAME}" + echo "${NAME} container started" +fi + +# go to saved location +cd "${DIR}" diff --git a/PRA05_ANSWER/util/runlike-python.md b/PRA05_ANSWER/util/runlike-python.md new file mode 100644 index 00000000..4fdc4e23 --- /dev/null +++ b/PRA05_ANSWER/util/runlike-python.md @@ -0,0 +1,39 @@ +# instalar runlike con python + +``` +#!/bin/bash + +# instalar runlike con python +mkdir -p ~/scripts +mkdir -p ~/scripts/runlike +cd ~/scripts/runlike + +# si no esta instalado venv +sudo apt install python3.12-venv +python3 -m venv .venv +source .venv/bin/activate +pip install runlike +deactivate + +IFS='' read -r -d '' SCRIPT <<'EOF' +#!/bin/bash + +DIR=$(pwd) +cd ~/scripts/runlike +source .venv/bin/activate +runlike "$@" +deactivate +cd "${DIR}" +EOF + +echo "${SCRIPT}" > ~/scripts/runlike.sh + +# añadir el alias a ~/.bash_aliases +echo "" >> ~/.bash_aliases +echo "alias runlike='bash ~/scripts/runlike.sh'" >> ~/.bash_aliases + +# hacer efectivo el alias +source ~/.bash_aliases + + +```