Skip to content

Commit

Permalink
feat(env): create dotenv file to use for makefile and gitlab ci varia…
Browse files Browse the repository at this point in the history
…bles
  • Loading branch information
mogtofu33 committed May 22, 2024
1 parent 0c91867 commit 62a995e
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 25 deletions.
30 changes: 21 additions & 9 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
variables:
IMAGE_VERSION: '1.3'
NODE_VERSION: '18'
BUILD_DIR: './drupal'
# Docker variables.
DOCKER_HOST: tcp://docker:2375
Expand All @@ -18,6 +16,7 @@ default:
- docker:dind
before_script:
- docker --version
- source VERSION.env
# Pull base image from Docker hub.
- docker pull --quiet $IMAGE_BASE || true
# Login to Gitlab and pull current image if exist.
Expand All @@ -28,10 +27,22 @@ default:
junit: junit.xml

stages:
- prepare
- build

env:
stage: prepare
image: alpine:latest
script:
- echo "Set env variables from dotenv."
artifacts:
reports:
dotenv: VERSION.env

.build_test:
stage: build
needs:
- env
script:
- echo "Build $IMAGE_VERSION with Drupal:$IMAGE_TAG PHP:$PHP_VERSION Node:$NODE_VERSION"
- PHP_VERSION="$PHP_VERSION" envsubst < "./drupal/tests/test_php.py" > "./drupal/tests/test_php.py"
Expand All @@ -48,7 +59,7 @@ stages:
$BUILD_DIR
- docker images
- docker push --quiet $CI_REGISTRY_IMAGE/$IMAGE
- if [[ -d ./$BUILD_DIR/tests ]]; then ./.gitlab-ci/run-tests.sh $CI_REGISTRY_IMAGE/$IMAGE; fi;
- if [[ -d $BUILD_DIR/tests ]]; then ./.gitlab-ci/run-tests.sh $CI_REGISTRY_IMAGE/$IMAGE; fi;
# Login to Docker hub and push.
- echo "$RELEASE_PASSWORD" | docker login $RELEASE_REGISTRY --username $RELEASE_USER --password-stdin
- docker push --quiet $RELEASE_IMAGE/$IMAGE
Expand All @@ -58,24 +69,25 @@ previous:
variables:
IMAGE_BASE: drupal:${IMAGE_TAG}-php${PHP_VERSION}
IMAGE: drupal-ci:${CI_COMMIT_BRANCH}-${IMAGE_TAG}
IMAGE_TAG: '10.1'
PHP_VERSION: '8.1'
IMAGE_TAG: $DRUPAL_PREVIOUS
PHP_VERSION: $DRUPAL_PREVIOUS_PHP

current:
extends: .build_test
variables:
IMAGE_BASE: drupal:${IMAGE_TAG}-php${PHP_VERSION}
IMAGE: drupal-ci:${CI_COMMIT_BRANCH}-${IMAGE_TAG}
IMAGE_TAG: '10.2'
PHP_VERSION: '8.2'
IMAGE_TAG: $DRUPAL_CURRENT
PHP_VERSION: $DRUPAL_CURRENT_PHP

# Enabled only when next version is stable
.next:
extends: .build_test
variables:
IMAGE_BASE: drupal:${IMAGE_TAG}-php${PHP_VERSION}
IMAGE: drupal-ci:${CI_COMMIT_BRANCH}-${IMAGE_TAG}
IMAGE_TAG: '11'
PHP_VERSION: '8.3'
IMAGE_TAG: $DRUPAL_NEXT
PHP_VERSION: $DRUPAL_NEXT_PHP

chrome-headless:
extends: .build_test
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Gitlab CI for Drupal CI Images Changelog

## 4.0 (2024-05-22)

### Features

* create dotenv file to use for makefile and gitlab ci variables
30 changes: 19 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
IMAGE_VERSION=1.3
NODE_VERSION=18
#!make

# Must match with .gitlab-ci.yml
DRUPAL_PREVIOUS=10.1
DRUPAL_PREVIOUS_PHP=8.1
DRUPAL_CURRENT=10.2
DRUPAL_CURRENT_PHP=8.2
DRUPAL_NEXT=11
DRUPAL_NEXT_PHP=8.2
.PHONY: help build test

ifneq (,$(wildcard ./VERSION.env))
include VERSION.env
endif

ifeq ($(origin IMAGE_VERSION),undefined)
$(error Missing env variable IMAGE_VERSION!)
endif

help:
@sed \
-e '/^[a-zA-Z0-9_\-]*:.*##/!d' \
-e 's/:.*##\s*/:/' \
-e 's/^\(.\+\):\(.*\)/$(shell tput setaf 6)\1$(shell tput sgr0):\2/' \
$(MAKEFILE_LIST) | column -c2 -t -s :

define build
@echo "Build $(1) with Drupal:$(2) PHP:$(3) Node:$(4)..."
Expand All @@ -30,12 +38,12 @@ define test
@docker exec -w /tests test-ci-$(1) pytest-3
endef

build:
build: ## Locally build images
$(call build,${IMAGE_VERSION},${DRUPAL_PREVIOUS},${DRUPAL_PREVIOUS_PHP},${NODE_VERSION})
$(call build,${IMAGE_VERSION},${DRUPAL_CURRENT},${DRUPAL_CURRENT_PHP},${NODE_VERSION})
# $(call build,${IMAGE_VERSION},${DRUPAL_NEXT},${DRUPAL_NEXT_PHP},${NODE_VERSION})

test:
test: ## Locally test images
$(call test,${DRUPAL_PREVIOUS})
$(call test,${DRUPAL_CURRENT})
# $(call test,${DRUPAL_NEXT})
8 changes: 8 additions & 0 deletions VERSION.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
IMAGE_VERSION=4.0
NODE_VERSION=20
DRUPAL_PREVIOUS=10.1
DRUPAL_PREVIOUS_PHP=8.1
DRUPAL_CURRENT=10.2
DRUPAL_CURRENT_PHP=8.2
DRUPAL_NEXT=10.3
DRUPAL_NEXT_PHP=8.2
2 changes: 1 addition & 1 deletion chrome-headless/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM debian:bullseye-slim

ARG IMAGE_VERSION='1.3'
ARG IMAGE_VERSION=1.0

LABEL name="chrome-headless"
LABEL maintainer="[email protected]"
Expand Down
8 changes: 4 additions & 4 deletions drupal/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
ARG IMAGE_TAG=10.2
ARG PHP_VERSION=8.2

# https://github.com/docker-library/drupal/blob/master/$IMAGE_TAG/php$PHP_VERSION/apache-buster/Dockerfile
# https://github.com/docker-library/drupal/blob/master/$IMAGE_TAG/php$PHP_VERSION
FROM drupal:${IMAGE_TAG}-php${PHP_VERSION}

ARG IMAGE_VERSION=1.0
ARG NODE_VERSION=20

ARG IMAGE_TAG=10.2
ARG PHP_VERSION=8.2
ARG NODE_VERSION=18
ARG IMAGE_VERSION=1.3

LABEL name="drupal-ci-${IMAGE_TAG}"
LABEL maintainer="[email protected]"
Expand Down Expand Up @@ -44,7 +45,6 @@ RUN \
#==================
# Install Nodejs, Yarn.
# https://github.com/nodesource/distributions#installation-instructions
# @todo replace with nvm?
RUN set -uex; \
mkdir -p /etc/apt/keyrings; \
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key \
Expand Down

0 comments on commit 62a995e

Please sign in to comment.