32
loading...
This website collects cookies to deliver better user experience
SSH_PRIVATE_KEY
private key variable listed, you can skip this step.SSH_PRIVATE_KEY
<ssh_private_key_details>
. (To generate a new SSH public and private key pair, follow steps from this guide. Make sure to not accidentally overwrite any existing key pairs.)Variable
authorized_keys
in the production server.ssh [email protected]
)Add the SSH public key to authorized_keys
nano ~/.ssh/authorized_keys
Paste the SSH public key(starts withssh-rsa
) in a new line
Save the file
.gitlab-ci.yml
in the root folder of your repository for CI/CD pipeline configurations.gitlab-ci.yml
in the root folderimage: node
cache:
paths:
- node_modules/
before_script:
- apt-get update -qq
- apt-get install -qq git
- "which ssh-agent || ( apt-get install -qq openssh-client )"
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
deploy:
stage: deploy
environment:
name: production
url: example.com
script:
- bash deploy/deploy.sh
only:
- master
node_modules
folder to improve the speed of the buildgit
package and then configure it to add our SSH_PRIVATE_KEY
StrictHostKeyChecking
to no
, to ensure git doesn't show manual prompt during initial connection.deploy
with a single pipeline stage deploy
which listens to commits on master
and runs the script in deploy/deploy.sh
deploy.sh
in deploy
folder#!/bin/bash
DEPLOY_SERVER=$DEPLOY_SERVER
SERVER_FOLDER="html-folder-in-server"
# Building React output
yarn install
yarn run build
echo "Deploying to ${DEPLOY_SERVER}"
scp -r build/ root@${DEPLOY_SERVER}:/var/www/html/${SERVER_FOLDER}/
echo "Finished copying the build files"
DEPLOY_SERVER
with value domain.com
for the repository using step 1.yarn
build
folder to /var/www/html/html-folder-in-server/build
location in serverubuntu
and empty tags.gitlab-ci.yml
and deploy/deploy.sh
files to master to start the automated deployment.active
, protected
and tags
to see if any of the conditions are incorrect.