Skip to content
Snippets Groups Projects

Tut01 test exercise

Closed Yana Kernerman requested to merge s92604/devops-webservice:tut01 into main
1 file
+ 29
23
Compare changes
  • Side-by-side
  • Inline
+ 29
23
workflow:
# rules:
# - if: $CI_PIPELINE_SOURCE == "merge_request_event"
# when: 'always'
# - if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_REF_NAME =~/main/
# - when: 'never'
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: 'always'
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_REF_NAME =~/main/
- when: 'never'
stages:
- test
@@ -13,16 +13,16 @@ stages:
# Main job to test the application
job_test_the_code:
stage: test
image: registry.hub.docker.com/library/golang:1.21 # Official Docker image provided by Go. It contains pre-configured environment for building and running Go applications.
image: registry.hub.docker.com/library/golang:1.21 # Official Docker image provided by Go
script:
- go get -t ./... # Installs dependencies, including those for testing
- go test -race -v ./... # Run tests with race detection enabled
job_build_artifact:
stage: build
# rules: # Conditions under which this job should run
# - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main" # Run this job only for merge request event into main.
# when: always
rules: # Conditions under which this job should run
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main" # Run this job only for merge request event into main
when: always
image: registry.hub.docker.com/library/golang:1.21
script:
- go get -t ./... # Installs dependencies
@@ -32,23 +32,29 @@ job_build_artifact:
- ./artifact.bin
expire_in: 1 week
job_build_and_publish_image:
job_publish_artifact:
stage: publish
# rules: # Conditions under which this job should run
# - if: $CI_PIPELINE_SOURCE == "push" && $CI_MERGE_COMMIT_REF_NAME =~ /main/ # Run this job only for merge request event into main.
# when: always
image: docker:24.0.0 # Official Docker image with Docker client installed
services:
- docker:24.0.0-dind # used to access the Docker daemon from within the CI job.
rules: # Conditions under which this job should run
- if: $CI_PIPELINE_SOURCE == "push" && $CI_MERGE_COMMIT_REF_NAME =~ /main/ # Run this job only for merge request event into main.
when: always
image: curlimages/curl:latest # Custom image with curl
tags:
- docker-privileged
dependencies:
- job_build_artifact
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
script:
- echo "Publishing artifact ..."
- ls -al
- TAG=$CI_COMMIT_REF_SLUG
- docker build --file ./Dockerfile --tag "$CI_REGISTRY_IMAGE:$TAG" .
- docker push "$CI_REGISTRY_IMAGE:$TAG"
\ No newline at end of file
- echo "Publishing artifact..."
- ls -al # List files to confirm artifact.bin exists
- pwd # Print the current directory
- echo "${CI_JOB_TOKEN}"
- echo " ${CI_API_V4_URL}"
- echo "${CI_PROJECT_ID}"
- echo "${CI_COMMIT_REF_NAME}"
- echo "${version}"
- curl --version # Verify curl installation
- |
curl \
--header "JOB-TOKEN: ${CI_JOB_TOKEN}" \
--upload-file ./artifact.bin \
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/artifacts/1.0.0/webservice"
Loading