gitlab-letsencrypt icon indicating copy to clipboard operation
gitlab-letsencrypt copied to clipboard

Automatic job renewal via scheduled pipelines

Open mishak87 opened this issue 6 years ago • 4 comments

To automatically renew certificates you could use Scheduled CI pipelines

  • [ ] Add master branch to protected branches if it is not there already
  • [ ] Add protected secret variable PRIVATE_TOKEN
  • [ ] Add renew job to .gitlab-ci.yml
stages:
  # ...
  - renew_ssl

renew_ssl:
  stage: renew_ssl
  script:
    - |
      if [ -z "${RENEW_SSL:-}" ]; then
        exit
      fi
      # TODO renew command
  only:
    - master
  • [ ] Create pipeline schedule
    interval pattern: 1 month target branch: master variables: RENEW_SSL = 1

I don't know if you can commit from CI job. If not using deployment key with allowed write access will be necessary.

mishak87 avatar Jan 17 '18 00:01 mishak87

@mishak87 This info would be very appreciated if it were on the readme

gabrielperales avatar Feb 02 '18 12:02 gabrielperales

+1 for this. I tried to implement it, but because a scheduled pipeline needs to complete before the challenge pipeline it can't work at the moment.

nathansmonk avatar Jun 11 '18 08:06 nathansmonk

I did it in my project https://gitlab.com/axil/axil.gitlab.io/blob/master/.gitlab-ci.yml.

Example:

letsencrypt:
  image: node:8-alpine
  stage: post-deploy
  variables:
    DOMAIN: "axilleas.me"
  before_script:
    - apk add git python --update-cache
    - npm install -g gitlab-letsencrypt --unsafe-perm
  script: |
    gitlab-le \
    --production \
    --domain $DOMAIN www.$DOMAIN \
    --email $LE_EMAIL \
    --token $LE_TOKEN \
    --repository $CI_PROJECT_URL \
    --path content/.well-known/acme-challenge
  only:
    - schedules

axilleas avatar Sep 08 '18 07:09 axilleas

@axilleas I have just tested it too. Thanks for examples. I will write blog post about bit more secure setup soon (tm). I do not like the "root" token available for all jobs and merge requests. It could be avoided setting up letsencrypt protected environment (only for project Maintainers) and setting CI variables to be available only for that environment.

mishak87 avatar Dec 12 '18 13:12 mishak87