diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..66adf9d --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,39 @@ +# GitLab CI for Activite + +stages: + - deploy + +deploy-job: + stage: deploy + rules: + - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"' + when: always + environment: production + before_script: + ## Install ssh-agent if not already installed, it is required by Docker. + - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )' + + ## Run ssh-agent (inside the build environment) + - eval $(ssh-agent -s) + + ## Give the right permissions, otherwise ssh-add will refuse to add files + ## Add the SSH key stored in SSH_PRIVATE_KEY file type CI/CD variable to the agent store + - chmod 400 "$SSH_PRIVATE_KEY" + - ssh-add "$SSH_PRIVATE_KEY" + + ## Create the SSH directory and give it the right permissions + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + + ## Put the scm to known hosts + - ssh-keyscan -t rsa gitea.ctisante.com >> ~/.ssh/known_hosts + + ## Set the git user name and email + - git config --global user.email "bender@ctisante.com" + - git config --global user.name "bender" + - git remote add gitea git@gitea.ctisante.com:cti/activite-gitlab.git + script: + - echo "Pushing to Public Repo..." + - git branch deploy + - git push -f gitea deploy:master + - echo "Activite module pushed." \ No newline at end of file