ci(gitlab-ci): separate frontend and backend downstreams

separate dynamic ci-yaml into two dynamic yamls for frontend and backend
This commit is contained in:
Sarah Vaupel 2024-08-24 17:30:14 +02:00
parent 333e8f7a9a
commit c177ff826e
4 changed files with 181 additions and 143 deletions

View File

@ -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:

73
.gitlab-ci/backend.yml Normal file
View File

@ -0,0 +1,73 @@
# SPDX-FileCopyrightText: 2024 Sarah Vaupel <sarah.vaupel@uniworx.de>
#
# 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

View File

@ -1,134 +0,0 @@
# SPDX-FileCopyrightText: 2024 Sarah Vaupel <sarah.vaupel@uniworx.de>
#
# 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

79
.gitlab-ci/frontend.yml Normal file
View File

@ -0,0 +1,79 @@
# SPDX-FileCopyrightText: 2024 Sarah Vaupel <sarah.vaupel@uniworx.de>
#
# 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