Skip to content

Commit

Permalink
Automate CWRC image updating from leaf-base-i8: first draft
Browse files Browse the repository at this point in the history
  • Loading branch information
jefferya committed Dec 13, 2024
1 parent 65e3e5a commit 908c672
Show file tree
Hide file tree
Showing 11 changed files with 466 additions and 1 deletion.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ The CWRC Repository customizations include Drupal modules and configurations tha

## Update

Note: 2024-12-13 - [./docker/drupal/scripts/auto.sh](./docker/drupal/scripts/auto.sh) is a first attempt at automating the update process described below.

* update repository versions
* Update `docker-bake.hcl` variable `LEAF_VERSION` with the container tag from <https://gitlab.com/calincs/cwrc/leaf/leaf-base-i8>
* Check if local files have changed in <https://gitlab.com/calincs/cwrc/leaf/leaf-base-i8> since that last local update
Expand Down Expand Up @@ -79,6 +81,26 @@ The CWRC Repository customizations include Drupal modules and configurations tha
$ mv /tmp/z docker/drupal/rootfs/var/www/drupal/config/sync/core.extension.yml
```

* `core.extensions`

* copy from leaf-base
``` bash
cp ../leaf-base-i8/docker/drupal/rootfs/var/www/drupal/config/sync/core.extension.yml docker/drupal/rootfs/var/www/drupal/config/sync/
```

* add back CWRC customizations
* core.extension.yml: `getjwtonlogin: 0` & `islandora_bagger_integration: 0`


``` bash
export FROM=ghcr.io/cwrc/drupal-core-extension-helper:local
docker buildx bake drupal-core-extension-helper --set "drupal.tags=${FROM}"
id=$(docker create "${FROM}")
docker cp $id:/tmp/core.extension.yml docker/drupal/rootfs/var/www/drupal/config/sync/core.extension.yml
docker rm -v $id
```


* `composer.json` & `composer.lock`

* copy from leaf-base
Expand Down
7 changes: 7 additions & 0 deletions docker-bake-leaf-version-override.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variable": {
"LEAF_VERSION": {
"default": "3.0.18"
}
}
}
31 changes: 30 additions & 1 deletion docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ variable "REPOSITORY" {
# Not the one displayed on DockerHub.
# Variable names with '_TAG' and '_REPOSITORY' fail with docker/bake-action
variable "LEAF_VERSION" {
default = "3.0.18"
default = "local"
}
variable "LEAF_REGISTRY" {
default = "registry.gitlab.com/calincs/cwrc/leaf/leaf-base-i8"
Expand Down Expand Up @@ -40,6 +40,34 @@ target "docker-metadata-action" {}
###############################################################################
# Helper Targets.
###############################################################################

target "leaf-version-update-helper" {
inherits = ["common"]
context = "."
dockerfile = "docker/drupal/Dockerfile-bake-update-helper"
contexts = {
}
tags = [
"${REPOSITORY}/leaf-version-update-helper:${TAG}"
]
args = {
LEAF_VERSION="${LEAF_VERSION}"
}
}


target "drupal-core-extension-helper" {
inherits = ["common"]
context = "docker/drupal"
dockerfile = "Dockerfile-core-extensions-helper"
contexts = {
}
tags = [
"${REPOSITORY}/drupal-core-extension-helper:${TAG}"
]
}


target "drupal-composer-helper" {
inherits = ["common"]
context = "docker/drupal"
Expand All @@ -52,6 +80,7 @@ target "drupal-composer-helper" {
]
}


###############################################################################
# Target.
###############################################################################
Expand Down
31 changes: 31 additions & 0 deletions docker/drupal/Dockerfile-bake-update-helper
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# syntax=docker/dockerfile:1.5.1
FROM python:3.12-alpine

ARG \
TARGETARCH \
LEAF_VERSION


ENV \
LEAF_VERSION ${LEAF_VERSION}


# Copy local customizations
COPY --link docker/drupal/scripts /scripts/

COPY --link docker-bake-leaf-version-override.json /tmp/docker-bake-leaf-version-override.json

# Update docker-bake with the specified LEAF version
# * core.extension
RUN --mount=type=cache,id=custom-drupal-composer-${TARGETARCH},sharing=locked,target=/root/.composer/cache \
export VIRTUAL_ENV=venv && \
python -m venv ${VIRTUAL_ENV} && \
source ${VIRTUAL_ENV}/bin/activate && \
python -m pip install python-hcl2 && \
echo "Running ${LEAF_VERSION}" && \
python /scripts/leaf_version_bake.py \
--src /tmp/docker-bake-leaf-version-override.json \
--value "${LEAF_VERSION}"

# export PATH=$PATH:/scripts/merge_cwrc/bin && \

25 changes: 25 additions & 0 deletions docker/drupal/Dockerfile-core-extensions-helper
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# syntax=docker/dockerfile:1.5.1
FROM python:3.12-alpine

ARG TARGETARCH

# Copy local customizations
COPY --link scripts /scripts/

COPY --link rootfs /


# Add CWRC customizations to
# * core.extension
RUN --mount=type=cache,id=custom-drupal-composer-${TARGETARCH},sharing=locked,target=/root/.composer/cache \
export VIRTUAL_ENV=/scripts/merge_cwrc_venv && \
python -m venv ${VIRTUAL_ENV} && \
source ${VIRTUAL_ENV}/bin/activate && \
python -m pip install pyyaml && \
python /scripts/merge_cwrc_customizations_drupal_core_extensions_yaml.py \
--input /scripts/core.extension_cwrc_customizations_template.yml \
--input /var/www/drupal/config/sync/core.extension.yml \
--output /tmp/core.extension.yml

# export PATH=$PATH:/scripts/merge_cwrc/bin && \

168 changes: 168 additions & 0 deletions docker/drupal/scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
#uv.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
37 changes: 37 additions & 0 deletions docker/drupal/scripts/auto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

# Get remote LEAF tag
LEAF_VERSION=$(
git ls-remote --tags https://gitlab.com/calincs/cwrc/leaf/leaf-base-i8.git | \
awk -F/ '{print $NF}' | \
grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | \
sort -V | \
tail -n1
)
echo $LEAF_VERSION

# Check Docker Buildx Bake
# If TAG and bake var different then update
export FROM=ghcr.io/cwrc/leaf-version-update-helper:local
LEAF_VERSION=${LEAF_VERSION} docker buildx bake -f docker-bake.hcl -f docker-bake-leaf-version-override.json leaf-version-update-helper --set "drupal.tags=${FROM}"
id=$(docker create "${FROM}")
docker cp $id:/tmp/docker-bake-leaf-version-override.json .
docker rm -v $id

# update Drupal core.extension.yml
wget --output-document docker/drupal/rootfs/var/www/drupal/config/sync/core.extension.yml https://gitlab.com/calincs/cwrc/leaf/leaf-base-i8/-/raw/${LEAF_VERSION}/docker/drupal/rootfs/var/www/drupal/config/sync/core.extension.yml

export FROM=ghcr.io/cwrc/drupal-core-extension-helper:local
docker buildx bake drupal-core-extension-helper --set "drupal.tags=${FROM}"
id=$(docker create "${FROM}")
docker cp $id:/tmp/core.extension.yml docker/drupal/rootfs/var/www/drupal/config/sync/core.extension.yml
docker rm -v $id

# Update Drupal composer.json and composer.lock
wget --output-document docker/drupal/rootfs/var/www/drupal/composer.json https://gitlab.com/calincs/cwrc/leaf/leaf-base-i8/-/raw/${LEAF_VERSION}/docker/drupal/rootfs/var/www/drupal/composer.json
wget --output-document docker/drupal/rootfs/var/www/drupal/composer.lock https://gitlab.com/calincs/cwrc/leaf/leaf-base-i8/-/raw/${LEAF_VERSION}/docker/drupal/rootfs/var/www/drupal/composer.lock

docker buildx bake -f docker-bake.hcl -f docker-bake-leaf-version-override.json drupal-composer-helper --set "drupal.tags=ghcr.io/cwrc/drupal:local"
id=$(docker create "ghcr.io/cwrc/drupal:local")
docker cp $id:/var/www/drupal/composer.json docker/drupal/rootfs/var/www/drupal/
docker cp $id:/var/www/drupal/composer.lock docker/drupal/rootfs/var/www/drupal/
docker rm -v $id
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module:
getjwtonlogin: 0
islandora_bagger_integration: 0
Loading

0 comments on commit 908c672

Please sign in to comment.