How do I setup auto-deploy from GitLab repo to Meteor Galaxy?

Hello, the idea here is to every time a specific branch of my repository (GitLab) is updated it should make a new deploy to the Meteor Galaxy. Has anyone done it? Do you know a tutorial for this?

We don’t use GitLab, but it looks like GitLab CI/CD is similar to Bitbucket Pipelines, which we do use to deploy to Galaxy on commits to both our staging and production git branches.

It looks like from the quickstart guide that you just need to create a YAML file in your git repo root and configure your project to use Runner. Probably want to make sure to use an OS image with Node 8 installed. Your YAML file will at a minimum need to include some Meteor specific commands to install Meteor and then call the meteor deploy command.

Also, you will need to generate a Meteor login session token (expires I think after 90 days) and copy it into a GitLab environment variable named something like DEPLOY_SESSION_FILE. To generate the token you need to be able to login in to Meteor as your Galaxy user before executing this command from your local development console:

$ METEOR_SESSION_FILE=deployment_token.json meteor login

I can’t give you an exact working script as I have no way to test it. However this should give you a general idea of what you need to put in your YAML file to deploy a staging branch and you can figure out the exact required syntax. Report back when you get a working script.

image: node:8

before_script:
  - curl https://install.meteor.com/ | sh
  - meteor npm install

deployStaging:
  script:
    - echo $DEPLOY_SESSION_FILE > deployment_token.json
    - METEOR_SESSION_FILE=deployment_token.json DEPLOY_HOSTNAME=galaxy.meteor.com meteor deploy --allow-superuser myApp-staging.meteorapp.com --settings config/staging/settings.json --owner username

  only:
    - staging
  tags:
    - docker
2 Likes

Any update on this? I am entertaining the idea of trying this also…

Hi,

Just had success deploying with the following .gitlab-ci.yml in case it helps others who wish to give Gitlab a spin:

deploy_staging:
image: node:8.15.1
before_script:

  • echo Installing Meteor…
  • curl https://install.meteor.com/?release=1.8.1 | sh
  • echo Installing NPM packages …
  • meteor npm install
    script:
  • echo deploying…
  • echo $DEPLOY_SESSION_FILE > deployment_token.json
  • DEPLOY_HOSTNAME=galaxy.meteor.com
  • echo $STAGING_SETTINGS_FILE > staging-settings.json
  • METEOR_SETTINGS=staging-settings.json
  • METEOR_SESSION_FILE=deployment_token.json meteor deploy --allow-superuser mygroovyapp.meteorapp.com

Hello.

We do want to use Bitbucket pipelines to deploy to Galaxy on commits to our production branch, however we cannot get this thing working. I would appreciate any hint about it.

Thanks in advance.

Here is an example bitbucket-pipelines.yml file. This deploy works when we push to our production branch on Bitbucket. We have a bunch of informational commands to just output to the Pipelines log, but you can skip those if you want. As I said earlier, make sure you generate your Meteor deployment token and copy to the Pipelines environment variable DEPLOY_SESSION_FILE first.

image: node:12
options:
  size: 2x
  
pipelines:
  branches:
    production:
      - step:
          deployment: production
          script:
            - npm --version
            - node --version
            - curl https://install.meteor.com/ | sh
            - echo $DEPLOY_SESSION_FILE > deployment_token.json
            - cat deployment_token.json
            - cd yourApp
            - meteor --version --allow-superuser
            - meteor npm --version
            - meteor node --version
            - meteor npm install --verbose
            - export TOOL_NODE_FLAGS="--max_old_space_size=4096"
            - METEOR_SESSION_FILE=../deployment_token.json DEPLOY_HOSTNAME=galaxy.meteor.com meteor deploy --allow-superuser yourApp.meteorapp.com --settings ../config/settings.json --owner yourOwnerName

Good luck.

Hello, thank you very much for your help.

We use the example you shared to create our own pipeline, using the deployment_token.json generated from the console, but we encountered this error:

image

It doesn’t seem to be generated by the settings.json file, as we use this file in manual deployments with no problem. On the other hand, the deployment_token.json file is generated automatically, and we have not modified it.

I would appreciate if you could give us any hints on how to fix this error.

1 Like
image: blurri/meteor-node

variables:
    METEOR_ALLOW_SUPERUSER: "true"

services:
  - mongo

cache:
  paths:
    - "node_modules"
    - "~/.npm"
    - "~/.meteor"
    - "~/meteor"

stages:
  - build
  - test
  - deploy

build:
  stage: build
  artifacts:
    paths:
      - ~/.meteor
      - .meteor/local
      - node_modules/
  script:
    - meteor npm install

# Run Spec Tests
#
# We always run spec tests on all branches and commits
#
# The linter is automatically called at this point
# as a sort of pre-flight before the tests
spec_tests:
  coverage: /^Statements\s*:\s*([^%]+)/
  stage: test
  script:
    - CI=false meteor npm run test

# Run Integration Tests
#
# Integration tests run before we touch any important
# branches (develop + master)
integration_tests:
  only:
    - dev
    - master
  stage: test
  script:
    - CI=false meteor npm run test

## Deploy to Staging Server
production:
  only:
    - staging
  type: deploy
  stage: deploy
  image: ruby:2.3.0
  script:
    - gem install dpl
    - dpl --provider=heroku --app=biowaze-staging --api-key=$HEROKU_API_KEY_STAGING

we are using heroku for our app, and this is the deploy script that worked for me. I met the same error with superuser you did, it is something about permissions in the gitlab runner docker that makes meteor build scream in agony. So we used a ruby image to deploy to a node machine.

Not the cleanest method, but it works.