diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0850dae742b5f6813f7e3fcc4ef0d9ade4eec8b2..00db35030531151977817c39857c36a92b4e671e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,10 +1,61 @@ + .build_container_image: + image: + name: gcr.io/kaniko-project/executor:debug + entrypoint: [''] + variables: + DOCKERFILE_LOCATION: 'unset' + CONTAINER_NAME: 'unset' + TAG_NAME: 'unset' + script: + - mkdir -p /kaniko/.docker + - echo "DOCKERFILE_LOCATION" $DOCKERFILE_LOCATION + - echo "CONTAINER_NAME" $CONTAINER_NAME + - echo "TAG_NAME" $TAG_NAME + - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json + - | + if [[ "$CREATE_LATEST_TAG" == "true" ]]; + then + /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $DOCKERFILE_LOCATION --destination $CI_REGISTRY_IMAGE/$CONTAINER_NAME:$TAG_NAME --destination $CI_REGISTRY_IMAGE/$CONTAINER_NAME:latest + else + /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $DOCKERFILE_LOCATION --destination $CI_REGISTRY_IMAGE/$CONTAINER_NAME:$TAG_NAME; + fi -stages: - - build - - test - + + stages: + - print:readme + - commit:dev_build + - commit:test + - commit:code_analysis + - commit:verify_analysis + - commit:release_build + - staging:deploy + - production:deploy -build_application: - stage: build - script: - echo " This will be the gitlab file for building the pipeline that includes 3 stages. And these will be build, test and deploy" \ No newline at end of file + + ################################################## + # Tasks of "commit"- Stage + ################################################## + + variables: + DEVELOPMENT_CONTAINER_NAME: 'development-container' + DEVELOPMENT_CONTAINER_TAG: "${CI_COMMIT_BRANCH}_${CI_COMMIT_SHORT_SHA}" #eindeutiger Tag durch "SHA" Hash + RELEASE_CONTAINER_NAME: 'release-container' + RELEASE_CONTAINER_TAG: "${CI_COMMIT_BRANCH}_${CI_COMMIT_SHORT_SHA}" #eindeutiger Tag durch "SHA" Hash + + + # build development container image + create_development_container_image: + stage: commit:dev_build + extends: + - .build_container_image + variables: + DOCKERFILE_LOCATION: $CI_PROJECT_DIR/app/Dockerfile + CONTAINER_NAME: $DEVELOPMENT_CONTAINER_NAME + TAG_NAME: $DEVELOPMENT_CONTAINER_TAG + CREATE_LATEST_TAG: 'true' + only: + - branches + - merge_requests + - main + except: + - schedules \ No newline at end of file