from Gitlab

New: quantum-cli v3, our PaaS: Runway 🚀

Deployments with Gitlab #

Gitlab is GIT-based version control server. They offer a cloud solution (hosted/managed) and also allow for on-premise installations. The software is free for most cases. Here’s a Gitlab CI Pipeline to deploy the Wordpress example application via Gitlab to our platform using their managed offering on Gitlab.com.

This Pipeline has multiple stages which assume a PR-based workflow and try to validate and test as much as they can before the deploy stage is executed.

Requirements #

Gitlab Pipeline #

💡 New in Quantum-CLI v3: Use our GitLab CI/CD catalog component.
include:
  - component: gitlab.com/runway-paas/oss/quantum/setup@1.0.0
    inputs:
      api-key: $QUANTUM_API_KEY

my-job:
  stage: build
  needs: [setup-quantum-cli]
  script:
    - ./quantum-cli --help
On-premise GitLab installations need to fork (pull-mirror) the component to be able to use it.

The component is open-source and published on GitLab.com. Feel free to request features there, or get in touch.

Manual #

You may also use our custom GitLab Docker image, the following is an example of a complete .gitlab-ci.yml file (pipeline), which is part of your project:

# re-usable
.jobdef: &job-docker-def
  image: docker:latest
  stage: build
  services:
    - docker:dind
  # this requires the variables to be defined in project settings
  before_script:
    - docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" $DOCKER_REGISTRY

.jobcompose: &job-compose-def
  image:
    name: docker/compose:1.24.1
    entrypoint: ["/bin/sh", "-c"]
  stage: test
  services:
    - docker:dind

# these are stages
stages:
  - build
  - test
  - predeploy
  - deploy

# inline variables :-)
variables:
  DOCKER_REGISTRY: registry.gitlab.com
  NGINX_IMAGE: $DOCKER_REGISTRY/YOUR-NAME/YOUR-PROJECT/nginx
  QUANTUM_CLI: r.planetary-quantum.com/quantum-public/cli-gitlab:3
  DOCKER_SERVER: YOUR-CLUSTER
  STACK_NAME: your-cluster-wordpressdemo

# these are our jobs
test-compose:
  <<: *job-compose-def
  before_script:
    - docker-compose version
  script:
    - docker-compose config -q

test-compose-dev:
  <<: *job-compose-def
  script:
    - docker-compose -f docker-compose.dev.yml config -q
  except:
    - master

test-quantum-credentials:
  image: $QUANTUM_CLI
  stage: test
  script:
    - quantum-cli ep ls

build-nginx-pr:
  <<: *job-docker-def
  script:
    - docker build -t $NGINX_IMAGE:$CI_COMMIT_SHORT_SHA -f Dockerfile.nginx .
  except:
    - master

build-nginx-master:
  <<: *job-docker-def
  script:
    - docker build -t $NGINX_IMAGE:latest -f Dockerfile.nginx .
    - docker push $NGINX_IMAGE:latest
  only:
    - master

# the following requires the QUANTUM_API_KEY env variable
update-website:
  image: $QUANTUM_CLI
  stage: deploy
  # list endpoints (as a test)
  before_script:
    - quantum-cli e ls
  script:
    - quantum-cli stack deploy --endpoint $DOCKER_SERVER --stack $STACK_NAME
  only:
    - master