From c177ff826ec9ffbd210faa29cc5c1da82e107654 Mon Sep 17 00:00:00 2001 From: Sarah Vaupel Date: Sat, 24 Aug 2024 17:30:14 +0200 Subject: [PATCH] ci(gitlab-ci): separate frontend and backend downstreams separate dynamic ci-yaml into two dynamic yamls for frontend and backend --- .gitlab-ci.yml | 38 ++++++--- .gitlab-ci/backend.yml | 73 +++++++++++++++++ .gitlab-ci/dynamic-gitlab-ci.yml | 134 ------------------------------- .gitlab-ci/frontend.yml | 79 ++++++++++++++++++ 4 files changed, 181 insertions(+), 143 deletions(-) create mode 100644 .gitlab-ci/backend.yml delete mode 100644 .gitlab-ci/dynamic-gitlab-ci.yml create mode 100644 .gitlab-ci/frontend.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 256a3d687..ea3b96aad 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,6 +23,11 @@ # - if: $CI_COMMIT_TAG =~ /^t/ # - if: $CI_COMMIT_TAG =~ /^d/ + +variables: + IMAGE_BUILDER: quay.io/buildah/stable:latest + + default: image: name: ${CI_REGISTRY}/uniworx/containers/debian:12.5 @@ -37,34 +42,49 @@ default: stages: - - dynamic + - prepare + - frontend + - backend - release # TODO -# TODO: documentation + dynamic:prepare: - stage: dynamic + stage: prepare before_script: - apt-get -y update - apt-get -y install git script: - FRONTEND_IMAGE_VERSION=`git log docker/frontend/Dockerfile | grep '^commit' | wc --lines` - BACKEND_IMAGE_VERSION=`git log docker/backend/Dockerfile | grep '^commit' | wc --lines` - - cat .gitlab-ci/dynamic-gitlab-ci.yml | .gitlab-ci/dynamci.pl FRONTEND_IMAGE_VERSION=${FRONTEND_IMAGE_VERSION} BACKEND_IMAGE_VERSION=${BACKEND_IMAGE_VERSION} > dynamic-gitlab-ci.yml + - cat .gitlab-ci/frontend.yml | .gitlab-ci/dynamci.pl FRONTEND_IMAGE_VERSION=${FRONTEND_IMAGE_VERSION} > frontend.yml + - cat .gitlab-ci/backend.yml | .gitlab-ci/dynamci.pl BACKEND_IMAGE_VERSION=${BACKEND_IMAGE_VERSION} > backend.yml artifacts: paths: - - dynamic-gitlab-ci.yml + - frontend.yml + - backend.yml -# TODO: documentation -dynamic:execute: - stage: dynamic +frontend: + stage: frontend needs: - dynamic:prepare trigger: strategy: depend include: - - artifact: dynamic-gitlab-ci.yml + - artifact: frontend.yml job: dynamic:prepare +backend: + stage: backend + needs: + - dynamic:prepare + - frontend + trigger: + strategy: depend + include: + - artifact: frontend.yml + job: dynamic:prepare + + # frontend dependencies: # stage: setup # cache: diff --git a/.gitlab-ci/backend.yml b/.gitlab-ci/backend.yml new file mode 100644 index 000000000..a3424efc9 --- /dev/null +++ b/.gitlab-ci/backend.yml @@ -0,0 +1,73 @@ +# SPDX-FileCopyrightText: 2024 Sarah Vaupel +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +### IMPORTANT NOTICE ### +# Our pipeline consists of static and dynamic parts. +# +# This file only contains the dynamic parts of our pipeline. +# Static jobs are defined in .gitlab-ci.yml. +# +# The marker "#dyn#" (without quotes) will be replaced by concrete values. +### + +variables: + BACKEND_IMAGE_VERSION: #dyn# + +stages: + - container + - compile + - lint + - test + + +container: + stage: container + image: ${IMAGE_BUILDER} + script: + - buildah bud -t backend/${CI_COMMIT_REF_SLUG}:${BACKEND_IMAGE_VERSION} docker/backend/Dockerfile + - buildah push --creds "${CI_REGISTRY_USER}:${CI_JOB_TOKEN}" backend/${CI_COMMIT_REF_SLUG}:${BACKEND_IMAGE_VERSION} ${CI_REGISTRY_IMAGE}/backend/${CI_COMMIT_REF_SLUG}:${BACKEND_IMAGE_VERSION} + rules: + - changes: + - docker/backend/Dockerfile + interruptible: false + + +compile: + stage: compile + needs: + - job: container + optional: true + image: &backend-image ${CI_REGISTRY_IMAGE}/backend/${CI_COMMIT_REF_SLUG}:${BACKEND_IMAGE_VERSION} + script: + - &load-backend-image zcat docker/backend/image.tar.gz | podman image load + - make -- --docker-run-backend-build FRADRIVE_SERVICE=backend CONTAINER_RUNNER=podman-compose + artifacts: + paths: + - /fradrive/.stack/ + - /fradrive/.stack-work/ + cache: &backend-cache + +lint: + stage: lint + needs: + - job: container + optional: true + image: *backend-image + script: + - *load-backend-image + - make -- --docker-run-backend-lint FRADRIVE_SERVICE=backend CONTAINER_RUNNER=podman-compose + cache: *backend-cache + +test: + stage: test + needs: + - job: container + optional: true + - job: backend build + artifacts: true + image: *backend-image + script: + - *load-backend-image + - make -- --docker-run-backend-test FRADRIVE_SERVICE=backend CONTAINER_RUNNER=podman-compose + cache: *backend-cache \ No newline at end of file diff --git a/.gitlab-ci/dynamic-gitlab-ci.yml b/.gitlab-ci/dynamic-gitlab-ci.yml deleted file mode 100644 index 9ff85c702..000000000 --- a/.gitlab-ci/dynamic-gitlab-ci.yml +++ /dev/null @@ -1,134 +0,0 @@ -# SPDX-FileCopyrightText: 2024 Sarah Vaupel -# -# SPDX-License-Identifier: AGPL-3.0-or-later - -### IMPORTANT NOTICE ### -# Our pipeline consists of static and dynamic parts. -# -# This file only contains the dynamic parts of our pipeline. -# Static jobs are defined in .gitlab-ci.yml. -# -# The marker "#dyn#" (without quotes) will be replaced by concrete values. -### - -variables: - FRONTEND_IMAGE_VERSION: #dyn# - BACKEND_IMAGE_VERSION: #dyn# - -stages: - - containers - - compile - - lint - - test - - -containers:frontend: - stage: containers - image: &buildah quay.io/buildah/stable:latest - script: - # - IMAGE_VERSION=`git log docker/frontend/Dockerfile | grep '^commit' | wc --lines` - - buildah bud -t frontend/${CI_COMMIT_REF_SLUG}:${FRONTEND_IMAGE_VERSION} docker/frontend/Dockerfile - - buildah push --creds "${CI_REGISTRY_USER}:${CI_JOB_TOKEN}" frontend/${CI_COMMIT_REF_SLUG}:${FRONTEND_IMAGE_VERSION} ${CI_REGISTRY_IMAGE}/frontend/${CI_COMMIT_REF_SLUG}:${FRONTEND_IMAGE_VERSION} - rules: - - changes: - - docker/frontend/Dockerfile - interruptible: false - -containers:backend: - stage: containers - image: *buildah - script: - # - IMAGE_VERSION=`git log docker/backend/Dockerfile | grep '^commit' | wc --lines` - - buildah bud -t backend/${CI_COMMIT_REF_SLUG}:${BACKEND_IMAGE_VERSION} docker/backend/Dockerfile - - buildah push --creds "${CI_REGISTRY_USER}:${CI_JOB_TOKEN}" backend/${CI_COMMIT_REF_SLUG}:${BACKEND_IMAGE_VERSION} ${CI_REGISTRY_IMAGE}/backend/${CI_COMMIT_REF_SLUG}:${BACKEND_IMAGE_VERSION} - rules: - - changes: - - docker/backend/Dockerfile - interruptible: false - - -frontend build: - stage: compile - needs: - - job: containers:frontend - optional: true - image: &frontend-image ${CI_REGISTRY_IMAGE}/frontend/${CI_COMMIT_REF_SLUG}:${FRONTEND_IMAGE_VERSION} - script: - - &load-frontend-image zcat docker/frontend/image.tar.gz | podman image load - - make -- --docker-run-frontend-build FRADRIVE_SERVICE=frontend CONTAINER_RUNNER=podman-compose - artifacts: - paths: - - /fradrive/node_modules - - /fradrive/well-known - cache: - - &frontend-cache - key: default-frontend - paths: - - /fradrive/.npm/ - - /fradrive/.well-known-cache/ - -frontend lint: - stage: lint - needs: - - job: containers:frontend - optional: true - image: *frontend-image - script: - - *load-frontend-image - - make -- --docker-run-frontend-lint FRADRIVE_SERVICE=frontend CONTAINER_RUNNER=podman-compose - cache: *frontend-cache - -frontend test: - stage: test - needs: - - job: containers:frontend - optional: true - - job: frontend build - artifacts: true - image: *frontend-image - script: - - *load-frontend-image - - make -- --docker-run-frontend-test FRADRIVE_SERVICE=frontend CONTAINER_RUNNER=podman-compose - - cache: *frontend-cache - -backend build: - stage: compile - needs: - - job: containers:backend - optional: true - - job: frontend build - artifacts: true - image: &backend-image ${CI_REGISTRY_IMAGE}/backend/${CI_COMMIT_REF_SLUG}:${BACKEND_IMAGE_VERSION} - script: - - &load-backend-image zcat docker/backend/image.tar.gz | podman image load - - make -- --docker-run-backend-build FRADRIVE_SERVICE=backend CONTAINER_RUNNER=podman-compose - artifacts: - paths: - - /fradrive/.stack/ - - /fradrive/.stack-work/ - cache: &backend-cache - -backend lint: - stage: lint - needs: - - job: containers:backend - optional: true - image: *backend-image - script: - - *load-backend-image - - make -- --docker-run-backend-lint FRADRIVE_SERVICE=backend CONTAINER_RUNNER=podman-compose - cache: *backend-cache - -backend test: - stage: test - needs: - - job: containers:backend - optional: true - - job: backend build - artifacts: true - image: *backend-image - script: - - *load-backend-image - - make -- --docker-run-backend-test FRADRIVE_SERVICE=backend CONTAINER_RUNNER=podman-compose - cache: *backend-cache \ No newline at end of file diff --git a/.gitlab-ci/frontend.yml b/.gitlab-ci/frontend.yml new file mode 100644 index 000000000..89a0fd3e9 --- /dev/null +++ b/.gitlab-ci/frontend.yml @@ -0,0 +1,79 @@ +# SPDX-FileCopyrightText: 2024 Sarah Vaupel +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +### IMPORTANT NOTICE ### +# Our pipeline consists of static and dynamic parts. +# +# This file only contains the dynamic parts of our pipeline. +# Static jobs are defined in .gitlab-ci.yml. +# +# The marker "#dyn#" (without quotes) will be replaced by concrete values. +### + +variables: + FRONTEND_IMAGE_VERSION: #dyn# + +stages: + - container + - compile + - lint + - test + + +container: + stage: container + image: ${IMAGE_BUILDER} + script: + - buildah bud -t frontend/${CI_COMMIT_REF_SLUG}:${FRONTEND_IMAGE_VERSION} docker/frontend/Dockerfile + - buildah push --creds "${CI_REGISTRY_USER}:${CI_JOB_TOKEN}" frontend/${CI_COMMIT_REF_SLUG}:${FRONTEND_IMAGE_VERSION} ${CI_REGISTRY_IMAGE}/frontend/${CI_COMMIT_REF_SLUG}:${FRONTEND_IMAGE_VERSION} + rules: + - changes: + - docker/frontend/Dockerfile + interruptible: false + + +compile: + stage: compile + needs: + - job: container + optional: true + image: &frontend-image ${CI_REGISTRY_IMAGE}/frontend/${CI_COMMIT_REF_SLUG}:${FRONTEND_IMAGE_VERSION} + script: + - &load-frontend-image zcat docker/frontend/image.tar.gz | podman image load + - make -- --docker-run-frontend-build FRADRIVE_SERVICE=frontend CONTAINER_RUNNER=podman-compose + artifacts: + paths: + - /fradrive/node_modules + - /fradrive/well-known + cache: + - &frontend-cache + key: default-frontend + paths: + - /fradrive/.npm/ + - /fradrive/.well-known-cache/ + +lint: + stage: lint + needs: + - job: container + optional: true + image: *frontend-image + script: + - *load-frontend-image + - make -- --docker-run-frontend-lint FRADRIVE_SERVICE=frontend CONTAINER_RUNNER=podman-compose + cache: *frontend-cache + +test: + stage: test + needs: + - job: container + optional: true + - job: frontend build + artifacts: true + image: *frontend-image + script: + - *load-frontend-image + - make -- --docker-run-frontend-test FRADRIVE_SERVICE=frontend CONTAINER_RUNNER=podman-compose + + cache: *frontend-cache