Automate Plone Theme Uploader with Gitlab CI

The Issue

There are many instances where a development team, at least my team, want a smooth development to production pipeline with a version tracked theme. Manually, this is possible with Git and Plone Theme Uploader, which developer would pull the latest changes and execute the upload command or upload the theme via the theme control panel. The problem is, someone has to do it from the command line or manually zip it and upload it.

The Big Picture

  • A developer pushes the changes for the theme to the git repository.
  • The CI / CD tests the changes or other developers review the changes.
  • Once approved by other developers or the CI / CD, the changes merged into master.
  • Once merged, the lead developer can deploy the changes to the plone site by creating a new tag.

The Solution

  • Create a private gitlab variable by going to your CI / CD settings (https://gitlab.com//settings/ci_cd)
  • Expand the variable collapsed content, and enter your plonekey has the key and the content of .plonetheme-upload-cookie has the value. Afterwards, click save variables.
  • In your gitlab-ci.yml file, located in the root of your repository, add the following lines of code:
image: node:latest

deploy_theme:
 stage: deploy
 script:
  - sed -i "s/title = [[Title of your theme]]/title = [[Title of your theme]] $CI_COMMIT_REF_NAME/g" manifest.cfg
  - cat manifest.cfg
  - echo $plonekey > ../.plonetheme-upload-cookie
  - npm install -g bower
  - bower install --allow-root
  - cd ..
  - npm install -g plonetheme-upload
  - plonetheme-upload --enable [[namespace-your-theme]] [[url-for-your-plone-site]]
 only:
  - tags

For more information, visit https://jamaicandevelopers.com/Members/oshanebailey/automate-plone-theme-upload-with-gitlab

5 Likes

@b4oshany How do you handle cookie expiration time? You allow long cookie expiration dates for everyone?

You could store the credentials as a gitlab variable
https://docs.gitlab.com/ee/ci/variables/#variables

Just as David said, You can store the credentials as Gitlab variables.

In a previous project, I was skeptical about storing credentials as a Gitlab variable. I went to the lenght of storing the credentials as files inside of a password protected zip file, which was located in another password protected zip file. The gitlab variable that I had stored, was used to unzip the parent zip file, then was used with a salt factor + MD5 to unzip the folder with the credentials.

Yes, it was an overkill and too complicated. However, it was an alternative if vanilla Gitlab variable is an security issue.

Currently, I'm using vanilla Gitlab variable for the credentials and cookie.

Another beauty about auto-deployed theme using Gitlab is that you can setup Gitlab environments to deploy and rollback themes .

Updated deployment code using credentials:

image: node:latest

stages:
  - build
  - deploy

before_script:
 - sed -i "s/title = [[Title of your theme]]/title = [[Title of your theme]] $CI_COMMIT_REF_NAME/g" manifest.cfg
 - cat manifest.cfg
 - npm install -g bower
 - bower install --allow-root

on_success_upload_theme:
  stage: deploy
  script:
   - echo $plonekey > ../.plonetheme-upload-cookie
   - touch ../account.dat
   - echo "$ploneuser" >> ../account.dat
   - echo "$plonekey2" >> ../account.dat
   - cd ..
   - npm install -g plonetheme-upload
   - TESTOUTPUT=$(plonetheme-upload --enable [[namespace-your-theme]] [[url-for-your-plone-site]] < account.dat)
   - if [[ $TESTOUTPUT = *"Upload successful"* ]]; then echo "SUCCESS"; else "FAIL"; fi
  only:
   - tags
  when: on_success
  environment:
   name: production

Plone Foundation Code of Conduct