2

New to the Devop world so my terminology may be limited or incorrect. I have a self-hosted gitlab server. I had a "hello world" container project that spun up a "hello world" golang app. I was able to get the CI/CD pipeline set up that would build the container, push it to the self hosted gitlab container registry, and deploy it to a running Linode server. My next step is to docker compose the golang container with nginx and certbot. If I ssh into the server and clone the repository, it runs. Now I am trying to deploy the compose to a Linode server. That is where I am currently at the posting of the question(s).

(1) One way would be to use ssh in the pipeline to "git pull" and build/up the compose file just like I did running locally on the remote docker host.

(2) After trying to do some research on the subject, I ran across something about "docker context". It looks like I could point my runner running the pipeline to point the remote docker host, and then the build/up command would be working on that server. I started a "hello world" pipeline to test that idea, but now I "think" I am fighting a CI/CD issue. Just to test the syntax of the command, I copied/pasted it into the command line on the remote server, I know it needs to be ran on the runner it was just an easy place to test the syntax, it does not throw an error. This is a protected branch and is therefore feels like it needs to mask part of the command. Is that my problem?

So my docker context command is

testcontext-job:
  stage: testcontext
  image: docker:latest
  script:
    - docker context ls
    - export DOCKER_HOST
    - docker context create remote ‐‐docker host=ssh://[email protected]
    - docker context ls

Output of the job.

I tried to narrow down the questions, hoping to give context to better questions. If option 1 is an accepted practice, I will not waste more time chasing the "docker context" rabbit.

Maybe I need to look at a 3rd option. :-)

1
  • 1
    Welcome to DevOps! Can you try using another context name instead of "remote"?? Something like "my-remote"?? Commented Aug 8, 2024 at 7:16

1 Answer 1

1

Approach 1: SSH and Remote Docker Commands

This approach involves SSHing into your Linode server and manually running git pull and docker-compose up commands. This is a straightforward method but can be cumbersome to automate and manage.

deploy:
  stage: deploy
  script:
    - ssh [email protected] "cd /path/to/your/project && git pull && docker-compose up -d"

Approach 2: Docker Context

Using Docker Context allows you to manage Docker endpoints easily and execute commands on remote Docker hosts without manually SSHing into them

testcontext-job:
  stage: testcontext
  image: docker:latest
  script:
    - docker context create remote --docker "host=ssh://[email protected]"
    - docker context use remote
    - docker context ls
deploy:
  stage: deploy
  image: docker:latest
  script:
    - docker context use remote
    - docker-compose up -d

Be careful

Don't forget the quotations in your docker create context comment.

1
  • What about SSH Key to allow gitlab CI to connect to your ssh client (context)? Commented Jan 25 at 5:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.