Skip to content

Commit d479f36

Browse files
committed
Add pipelines
1 parent 747ae7e commit d479f36

17 files changed

+333
-3
lines changed

03-cd/02-gitlab/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
1. Permitimos registry inseguro a docker
1313
* En Linux En el fichero /etc/docker/dameon.json
1414
```
15-
{
16-
insecure-registries : [gitlab.local:5001]
17-
}
15+
{"insecure-registries" : ["gitlab.local:5001"]}
1816
```
1917
* En windows lo hacemos via Docker Desktop
2018

03-cd/02-gitlab/myimage/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ARG base_version
2+
ARG base_image_name
3+
FROM $base_image_name:$base_version
4+
ARG python_version
5+
RUN echo $python_version
6+
RUN apt-get update
7+
RUN apt-get install -y python$python_version

03-cd/02-gitlab/myimage/gitlab-ci.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
variables:
2+
PYTHON_VERSION: "3.9"
3+
BASE_VERSION: "20.04"
4+
BASE_IMAGE_NAME: "ubuntu"
5+
REGISTRY_PATH: "$CI_REGISTRY/$CI_PROJECT_PATH"
6+
7+
stages:
8+
- docker:build
9+
10+
11+
docker:build:
12+
stage: docker:build
13+
before_script:
14+
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $REGISTRY_PATH
15+
script:
16+
- docker build --build-arg base_image_name=$BASE_IMAGE_NAME --build-arg python_version=$PYTHON_VERSION --build-arg base_version=$BASE_VERSION -t $REGISTRY_PATH:$CI_COMMIT_TAG .
17+
- docker push $REGISTRY_PATH:$CI_COMMIT_TAG
18+
- echo "Pushed $IREGISTRY_PATH:$CI_COMMIT_TAG"
19+
only:
20+
variables:
21+
- $CI_COMMIT_TAG != null
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
stages:
2+
- stage1
3+
4+
testjob:
5+
stage: stage1
6+
script:
7+
- echo "Hola mundo"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
stages:
2+
- stage1
3+
image: python:3.8-slim
4+
5+
testjob:
6+
stage: stage1
7+
script:
8+
- echo "Hola mundo"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
variables:
2+
artifact: "fichero.txt"
3+
artifact_content: "Esto es el contenido de mi artifact"
4+
5+
6+
stages:
7+
- stage1
8+
- stage2
9+
10+
testjob:
11+
variables:
12+
artifact_content: "Esto es una variable de job"
13+
image: docker:19.03.13
14+
stage: stage1
15+
script:
16+
- echo $artifact_content >> $artifact
17+
artifacts:
18+
when: on_success
19+
paths:
20+
- $artifact
21+
only:
22+
- develop
23+
24+
testjob2:
25+
stage: stage2
26+
script:
27+
- cat $artifact
28+
only:
29+
- develop
30+
allow_failure: true
31+
environment:
32+
name: test
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
variables:
2+
artifact: "fichero.txt"
3+
artifact_content: "Esto es el contenido de mi artifact"
4+
5+
6+
stages:
7+
- stage0
8+
- stage1
9+
- stage2
10+
11+
allbranches:
12+
stage: stage0
13+
script:
14+
- echo "Esto lo ejecuto en todas las branches"
15+
16+
testjob:
17+
variables:
18+
artifact_content: "Esto es una variable de job"
19+
image: docker:19.03.13
20+
stage: stage1
21+
script:
22+
- echo $artifact_content >> $artifact
23+
artifacts:
24+
when: on_success
25+
paths:
26+
- $artifact
27+
only:
28+
- develop
29+
30+
testjob2:
31+
stage: stage2
32+
script:
33+
- cat $artifact
34+
only:
35+
- master
36+
when: manual
37+
allow_failure: true
38+
environment:
39+
name: test
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
stages:
2+
- build
3+
- deploy
4+
5+
6+
build:
7+
stage: build
8+
before_script:
9+
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY/$CI_PROJECT_PATH
10+
script:
11+
- echo $CI_REGISTRY $CI_REGISTRY_USER $CI_REGISTRY_PASSWORD
12+
- docker build -t $CI_REGISTRY/$CI_PROJECT_PATH/flaskapp:$CI_COMMIT_SHA .
13+
- docker push $CI_REGISTRY/$CI_PROJECT_PATH/flaskapp:$CI_COMMIT_SHA
14+
15+
deploy:
16+
stage: deploy
17+
before_script:
18+
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY/$CI_PROJECT_PATH
19+
script:
20+
- if [[ $(docker ps --filter "name=flaskapp" --format '{{.Names}}') == "flaskapp" ]]; then docker container rm -f flaskapp; else echo "No existe"; fi
21+
- docker run --name "flaskapp" -d -p 8080:8080 $CI_REGISTRY/$CI_PROJECT_PATH/flaskapp:$CI_COMMIT_SHA
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
stages:
2+
- maven:build
3+
- maven:test
4+
- docker:build
5+
- deploy
6+
maven:build:
7+
image: maven:3.6.3-jdk-8-slim
8+
stage: maven:build
9+
script:
10+
- mvn clean package
11+
artifacts:
12+
when: on_success
13+
paths:
14+
- "target/*.jar"
15+
16+
maven:ut:
17+
image: maven:3.6.3-jdk-8-slim
18+
stage: maven:test
19+
dependencies:
20+
- maven:build
21+
script:
22+
- mvn verify
23+
artifacts:
24+
when: on_success
25+
paths:
26+
- "target/"
27+
28+
build:
29+
stage: docker:build
30+
before_script:
31+
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY/$CI_PROJECT_PATH
32+
script:
33+
- echo $CI_REGISTRY $CI_REGISTRY_USER $CI_REGISTRY_PASSWORD
34+
- docker build -t $CI_REGISTRY/$CI_PROJECT_PATH:$CI_COMMIT_SHA .
35+
- docker push $CI_REGISTRY/$CI_PROJECT_PATH:$CI_COMMIT_SHA
36+
37+
deploy:
38+
stage: deploy
39+
before_script:
40+
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY/$CI_PROJECT_PATH
41+
script:
42+
- if [[ $(docker ps --filter "name=springapp" --format '{{.Names}}') == "springapp" ]]; then docker container rm -f springapp; else echo "No existe"; fi
43+
- docker run --name "springapp" -d -p 8080:8080 $CI_REGISTRY/$CI_PROJECT_PATH:$CI_COMMIT_SHA
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
stages:
2+
- stage1
3+
4+
image: docker:19.03.13
5+
6+
testjob:
7+
image: python:3.8-slim
8+
stage: stage1
9+
script:
10+
- echo "Hola mundo"

0 commit comments

Comments
 (0)