my personal site, so I can easily author my blog posts from nearly anywhere. Unfortunately, since this is a personal site, I’m not exactly spending the dollars on building out a full Continuous Integration / Delivery process.
GitHub provides Actions, a free for limited use solution for executing code on Git repository events. With GitHub Actions, I can set up a pipeline to automatically deploy my code on changes to the master branch.
The pipeline is defined as a YAML file, deploy.yaml, under the directory .github.workflows
in my code repository.
# Deploys code updates to my personal site on push to the master branch
name: Deploy on Push
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
server-id: github
settings-path: ${{ github.workspace }}
- name: Build and Deploy
run: mvn install -B -s $GITHUB_WORKSPACE/settings.xml -PautoInstallBundle,ci
env:
SLING_HOST: ${{ secrets.DEPLOY_HOST }}
SLING_USERNAME: ${{ secrets.DEPLOY_USERNAME }}
SLING_PASSWORD: ${{ secrets.DEPLOY_PASSWORD }}
SLING_PROTOCOL: https
SLING_PORT: 443
A few things to note about the pipeline definition:
on
object contains my invocation definition, in this case, pushes to masterci
, this profile will copy the environment variables seen in the env objectIn order to deploy my code, I have to provide the CMS authoring URL and the username / password for an Administrative user. Naturally, I don’t want to put this information on the web. With GitHub Actions, I can create secrets within the project:
And then use the ci
profile in the POM to copy those secrets as environment variables from the env
parameter in the Github Actions pipeline into the Maven project properties.
<profile>
<id>ci</id>
<properties>
<sling.host>${env.SLING_HOST}</sling.host>
<sling.port>${env.SLING_PORT}</sling.port>
<sling.username>${env.SLING_USERNAME}</sling.username>
<sling.password>${env.SLING_PASSWORD}</sling.password>
<sling.protocol>${env.SLING_PROTOCOL}</sling.protocol>
</properties>
</profile>
Once this is all wired up, you can push in a small change to execute the pipeline and you should see the deployment succeed. Note that the secrets are hidden from the logs so even if a user can see the pipeline, they cannot see the secret values.
With Github Actions, you can not only host a small Apache Sling CMS website for free, but you can even have a reliable CI/CD process!