diff --git a/Jenkinsfile b/Jenkinsfile index 8ff4f80..ee368fe 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,6 +3,11 @@ pipeline { agent { label 'docker' } + + parameters { + booleanParam(name: 'DEPLOY_STAGING', defaultValue: true, description: 'Deploy to index.staging.scheme.org') + booleanParam(name: 'DEPLOY_PROD', defaultValue: false, description: 'Deploy to index.scheme.org') + } stages { @@ -15,7 +20,7 @@ pipeline { stage('Build') { agent { docker { - image 'docker:cli' + image 'docker:20.10.24-cli' args "-u root" reuseNode true } @@ -30,25 +35,50 @@ pipeline { } } - stage('Deploy') { + stage('Deploy staging') { + agent { + dockerfile { + filename './deploy/rsync.Dockerfile' + reuseNode true + } + } + when { + expression { + return params.DEPLOY_STAGING + } + } + steps { + sshagent(credentials: ['index_staging_tuonela_ssh']) { + sh ''' + mkdir ~/.ssh + ssh-keyscan -t rsa tuonela.scheme.org >> ~/.ssh/known_hosts + rsync schemeindex.zip stag-index@tuonela.scheme.org:/staging/index/update/schemeindex.zip + ssh stag-index@tuonela.scheme.org 'cd ~ ; bash install-update.sh' + ''' + } + } + } + + stage('Deploy production') { agent { dockerfile { - filename './deploy/ansible.Dockerfile' + filename './deploy/rsync.Dockerfile' reuseNode true } } when { - branch 'master' + expression { + return params.DEPLOY_PROD + } } steps { - dir('deploy') { - sh 'pip install ansible' - sshagent(credentials: ['index_scheme_org_ssh']) { - sh ''' - ssh-keyscan -t rsa index.scheme.org >> ~/.ssh/known_hosts - ansible-playbook -i hosts deploy.yml -e content_zip_file=../schemeindex.zip - ''' - } + sshagent(credentials: ['index_tuonela_ssh']) { + sh ''' + mkdir ~/.ssh + ssh-keyscan -t rsa tuonela.scheme.org >> ~/.ssh/known_hosts + rsync schemeindex.zip prod-index@tuonela.scheme.org:/production/index/update/schemeindex.zip + ssh prod-index@tuonela.scheme.org 'cd ~ ; bash install-update.sh' + ''' } } } diff --git a/deploy/README.adoc b/deploy/README.adoc deleted file mode 100644 index 8fc2c29..0000000 --- a/deploy/README.adoc +++ /dev/null @@ -1,6 +0,0 @@ -= Ansible deployment of the static site - -This folder contains deployment playbook. It is presumed that target uses nginx and systemd. - -. Build the static site (see ../build folder) -. Invoke `ansible-playbook -i hosts deploy.yml -e content_zip_file=../build/schemeindex.zip` from this directory diff --git a/deploy/ansible.Dockerfile b/deploy/ansible.Dockerfile deleted file mode 100644 index a74d327..0000000 --- a/deploy/ansible.Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM python:3.9.20 -RUN useradd -ms /bin/bash ansible -USER ansible -RUN pip install ansible -ENV PATH="/home/ansible/.local/bin:$PATH" -RUN mkdir -p /home/ansible/.ssh diff --git a/deploy/deploy.yml b/deploy/deploy.yml deleted file mode 100644 index 060e913..0000000 --- a/deploy/deploy.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- -- name: 'Deploy scheme index' - hosts: 'index.scheme.org' - tasks: - - name: 'Upload nginx config' - template: - src: 'template/scheme_index.conf' - dest: '{{nginx_conf_d_location}}/scheme_index.conf' - - name: 'Ensure content root exists' - file: - name: '{{root_location}}' - state: 'directory' - - name: 'Upload scheme index content' - unarchive: - src: '{{content_zip_file}}' - dest: '{{root_location}}' - - name: 'Reload nginx service' - systemd_service: - name: 'nginx' - state: 'reloaded' - diff --git a/deploy/hosts b/deploy/hosts deleted file mode 100644 index d4b44dc..0000000 --- a/deploy/hosts +++ /dev/null @@ -1,7 +0,0 @@ -all: - hosts: - index.scheme.org: - ansible_user: root - certs_location: /etc/letsencrypt/live/index.scheme.org/ - nginx_conf_d_location: /etc/nginx/conf.d - root_location: /var/www/scheme_index diff --git a/deploy/rsync.Dockerfile b/deploy/rsync.Dockerfile new file mode 100644 index 0000000..57856cc --- /dev/null +++ b/deploy/rsync.Dockerfile @@ -0,0 +1,2 @@ +FROM ubuntu:24.04 +RUN apt-get update && apt-get install -y ssh rsync diff --git a/deploy/template/scheme_index.conf b/deploy/template/scheme_index.conf deleted file mode 100644 index 92ea659..0000000 --- a/deploy/template/scheme_index.conf +++ /dev/null @@ -1,26 +0,0 @@ -server { - - listen 443 ssl; - server_name index.scheme.org; - ssl_certificate {{certs_location}}/fullchain.pem; - ssl_certificate_key {{certs_location}}/privkey.pem; - - root {{root_location}}; - index index.html; - - location / { - try_files $uri $uri/ /index.html =404; - } - -} - -server { - - listen 80; - server_name index.scheme.org; - - location / { - return 301 https://$host$request_uri; - } - -}