From aee5c224d0a8e9014462cebafb83ac1b0f4cad4f Mon Sep 17 00:00:00 2001 From: ludo8147 <ludo8147@bht-berlin.de> Date: Wed, 4 Sep 2024 08:43:25 +0200 Subject: [PATCH] define and run a pipeline --- .gitlab-ci.yml | 65 ++++++++++++++---------- Define and run a pipeline/.gitlab-ci.yml | 1 + 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 946decb..ebdcae5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ -# Code aus Vorlesung -# https://docs.gitlab.com/ee/user/packages/container_registry/build_and_push_images.html -# https://docs.gitlab.com/ee/ci/docker/using_docker_build.html -# https://docs.gitlab.com/ee/ci/services/ +#Code: https://github.com/lucendio/lecture-devops-code/blob/master/tutorials/define-and-run-pipeline/.gitlab-ci.yml +# und Vorlesung +#https://docs.gitlab.com/ee/user/packages/container_registry/build_and_push_images.html +#https://docs.gitlab.com/ee/ci/yaml/workflow.html workflow: rules: @@ -9,7 +9,7 @@ workflow: when: always variables: - CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest + version: 0.0.$CI_PIPELINE_IID stages: - 'build' @@ -23,38 +23,47 @@ job_test: - go test -race -v ./... job_build: - stage: build - image: mirror.gcr.io/library/golang:1.21 + stage: 'build' + image: 'mirror.gcr.io/library/golang:1.21' + parallel: + matrix: + - GOOS: + - 'linux' + - 'windows' + - 'darwin' + GOARCH: + - 'amd64' + - 'arm64' before_script: - mkdir -p ./artifacts - script: - - go get -t ./... - - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 - go build - -o ./artifact.bin + script: + - | + go build \ + -o ./artifacts/webservice_${GOOS}_${GOARCH}.bin \ ./*.go artifacts: paths: - - ./artifact.bin - expire_in: 10 sec - + - ./artifacts -job_upload: - stage: publish - image: registry.hub.docker.com/library/docker:24.0.7 +job_publish: + stage: 'publish' + rules: + image: 'public.ecr.aws/lts/ubuntu:22.04' tags: - docker-privileged dependencies: - job_build - services: - - name: registry.hub.docker.com/library/docker:24.0.7-dind + before_script: + - apt update + - apt install -y ca-certificates curl + - update-ca-certificates script: - echo ${CONTAINER_RELEASE_IMAGE} - - docker build - --file ./Containerfile - --tag "${CONTAINER_RELEASE_IMAGE}" - ./ - - docker push $CONTAINER_RELEASE_IMAGE - after_script: - - docker image rm --force "${CONTAINER_RELEASE_IMAGE}" + - | + for artifact in ./artifacts/*; do + chmod +x ${artifact} + curl \ + --header "Job-TOKEN: ${CI_JOB_TOKEN}" \ + --upload-file ${artifact} \ + "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/artifacts/${version}/" + done diff --git a/Define and run a pipeline/.gitlab-ci.yml b/Define and run a pipeline/.gitlab-ci.yml index 0825c2b..b1423bc 100644 --- a/Define and run a pipeline/.gitlab-ci.yml +++ b/Define and run a pipeline/.gitlab-ci.yml @@ -1,5 +1,6 @@ #Code: https://github.com/lucendio/lecture-devops-code/blob/master/tutorials/define-and-run-pipeline/.gitlab-ci.yml # und Vorlesung +#https://docs.gitlab.com/ee/user/packages/container_registry/build_and_push_images.html workflow: rules: -- GitLab