How to make ssh deployment more clear in gitlab?

The ABC variables could be put into an .env file which is sourced at the beginning of the script. That file is stored in the Git repository (unless it contains credentials, never commit this into Git - consider populating them on-demand in CI/CD before_script sections).

Something like this, but beware I am not a good bash programmer - I asked GitLab Duo Chat to generate it for me, using the prompt Create a bash script which sources a .env file, checks if the docker CLI is installed, and pulls and runs a specific image, use python:3.11

#!/bin/bash

# Source .env file
source .env

# Check if docker is installed
if ! command -v docker &> /dev/null
then
    echo "docker could not be found"
    exit
fi

# Pull python image 
docker pull python:3.11

# Run image
docker run -it python:3.11

The CI/CD portions could look like the following.

Chat prompt for reference: Please show how to send a .env and deploy.sh script file over scp to a remote host, and then call the script over SSH. All in a CI/CD jobc

stages:
  - deploy

deploy_job:
  stage: deploy
  script:
    # Copy .env file to remote host
    - scp .env remote_user@remote_host:/path/to/app  

    # Copy deploy script to remote host
    - scp deploy.sh remote_user@remote_host:/path/to/app

    # SSH into remote host and run deploy script
    - ssh remote_user@remote_host "cd /path/to/app && ./deploy.sh"
1 Like