Skip to contentSkip to conversation

deploy to qemu-project.org from GitLab CI

PATCH Superseded Paolo Bonzini 3 participants 6 messages Jan 19, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 deploy to qemu-project.org from GitLab CI

Currently, the website is rebuilt on qemu-project.org using an update hook. We can reuse instead the Jekyll output of GitLab's CI.

To do so, a new user qemu-deploy has been created on qemu.org. The private key is stored into a file variable SSH_PRIVATE_KEY_FILE (be careful to include the trailing newline after "---END OPENSSH PRIVATE KEY---"!).

---
 .gitlab-ci.yml | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
.gitlab-ci.yml +28 -0
index 5fa3041..08b6d20 100644
@@ -1,6 +1,11 @@
 
+stages:
+  - build
+  - update
+
 pages:
   image: centos:8
+  stage: build
   cache:
     paths:
       - vendor
@@ -14,3 +19,26 @@ pages:
   artifacts:
     paths:
      - public
+
+deploy:
+  image: centos:8
+  stage: update
+  needs:
+    - job: pages
+      artifacts: true
+  before_script:
+    - dnf install -y openssh-clients rsync
+    - eval $(ssh-agent -s)
+    - cat "$SSH_PRIVATE_KEY_FILE" | tr -d '\r' | ssh-add -
+    - mkdir -m700 -p ~/.ssh
+    - - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" >> ~/.ssh/config'
+  script:
+    - ssh $SSH_DEPLOY_DESTINATION "cd /var/www/qemu-project.org && mkdir new && rsync -avz root/ new"
+    - rsync -avz public/ $SSH_DEPLOY_DESTINATION:/var/www/qemu-project.org/new
+    - ssh $SSH_DEPLOY_DESTINATION "cd /var/www/qemu-project.org && rm -rf old && mv root old && mv new root"
+  only:
+    refs:
+      - master
+    variables:
+      - $SSH_PRIVATE_KEY_FILE
+      - $SSH_DEPLOY_DESTINATION
Signature · 1 line
2.29.2
#1 lore raw
Quoted 3 lines · Paolo Bonzini

Currently, the website is rebuilt on qemu-project.org using an update hook. We can reuse instead the Jekyll output of GitLab's CI.

Are there any files present on the qemu-project.org webroot other than the published output of Jekyll ? QEMU had the good sense to use sub-domains git.qemu-project.org and download.qemu-project.org for other content. So maybe you just turn the root qemu-project.org and www.qemu-project.org domains into CNAME records pointing to the gitlab pages site ?

Quoted 25 lines
.gitlab-ci.yml +10 -0
index 5fa3041..08b6d20 100644
@@ -1,6 +1,11 @@
 
+stages:
+  - build
+  - update
+
 pages:
   image: centos:8
+  stage: build
   cache:
     paths:
       - vendor
@@ -14,3 +19,26 @@ pages:
   artifacts:
     paths:
      - public
+
+deploy:
+  image: centos:8
+  stage: update
+  needs:

.gitlab-ci.yml pages: · line 36

Quoted 10 lines
.gitlab-ci.yml +10 -0
+    - job: pages
+      artifacts: true
+  before_script:
+    - dnf install -y openssh-clients rsync
+    - eval $(ssh-agent -s)
+    - cat "$SSH_PRIVATE_KEY_FILE" | tr -d '\r' | ssh-add -
+    - mkdir -m700 -p ~/.ssh
+    - - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" >> ~/.ssh/config'
+  script:
+    - ssh $SSH_DEPLOY_DESTINATION "cd /var/www/qemu-project.org && mkdir new && rsync -avz root/ new"

Why copy the old root into the new root ? This means that any time we delete a file in git, it will never be removed from the live webroot.

.gitlab-ci.yml pages: · line 38

Quoted 2 lines
.gitlab-ci.yml +2 -0
+    - rsync -avz public/ $SSH_DEPLOY_DESTINATION:/var/www/qemu-project.org/new
+    - ssh $SSH_DEPLOY_DESTINATION "cd /var/www/qemu-project.org && rm -rf old && mv root old && mv new root"

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#2 lore raw
Quoted 11 lines · Daniel P. Berrangé
Quoted 3 lines · Paolo Bonzini

Currently, the website is rebuilt on qemu-project.org using an update hook. We can reuse instead the Jekyll output of GitLab's CI.

Are there any files present on the qemu-project.org webroot other than the published output of Jekyll ? QEMU had the good sense to use sub-domains git.qemu-project.org and download.qemu-project.org for other content. So maybe you just turn the root qemu-project.org and www.qemu-project.org domains into CNAME records pointing to the gitlab pages site ?

There are other files in the webroot at https://www.qemu.org/docs/master/, even though they're handled server side with the httpd Alias directive.

Right now they are built outside CI, from a cron job, but the plan is to do the same as qemu-web and deploy them during the GitLab CI run.

Quoted 30 lines
Quoted 30 lines
.gitlab-ci.yml +15 -0
index 5fa3041..08b6d20 100644
@@ -1,6 +1,11 @@
 
+stages:
+  - build
+  - update
+
  pages:
    image: centos:8
+  stage: build
    cache:
      paths:
        - vendor
@@ -14,3 +19,26 @@ pages:
    artifacts:
      paths:
       - public
+
+deploy:
+  image: centos:8
+  stage: update
+  needs:
+    - job: pages
+      artifacts: true
+  before_script:
+    - dnf install -y openssh-clients rsync
+    - eval $(ssh-agent -s)
Quoted 8 lines

.gitlab-ci.yml pages: · line 36

Quoted 5 lines
.gitlab-ci.yml +5 -0
+    - cat "$SSH_PRIVATE_KEY_FILE" | tr -d '\r' | ssh-add -
+    - mkdir -m700 -p ~/.ssh
+    - - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" >> ~/.ssh/config'
+  script:
+    - ssh $SSH_DEPLOY_DESTINATION "cd /var/www/qemu-project.org && mkdir new && rsync -avz root/ new"

Why copy the old root into the new root ? This means that any time we delete a file in git, it will never be removed from the live webroot.

To speed up the rsync below. The website is small, but it doesn't hurt.
However, you're right that "--delete" must be added to the next line.

Paolo

Quoted 8 lines

.gitlab-ci.yml pages: · line 38

Quoted 2 lines
.gitlab-ci.yml +2 -0
+    - rsync -avz public/ $SSH_DEPLOY_DESTINATION:/var/www/qemu-project.org/new
+    - ssh $SSH_DEPLOY_DESTINATION "cd /var/www/qemu-project.org && rm -rf old && mv root old && mv new root"

Regards,
Daniel

#3 lore raw
In reply to Paolo Bonzini
Quoted 19 lines · Paolo Bonzini

Currently, the website is rebuilt on qemu-project.org using an update hook. We can reuse instead the Jekyll output of GitLab's CI.

To do so, a new user qemu-deploy has been created on qemu.org. The private key is stored into a file variable SSH_PRIVATE_KEY_FILE (be careful to include the trailing newline after "---END OPENSSH PRIVATE KEY---"!).

---
  .gitlab-ci.yml | 28 ++++++++++++++++++++++++++++
  1 file changed, 28 insertions(+)
.gitlab-ci.yml +0 -0
index 5fa3041..08b6d20 100644

.gitlab-ci.yml line 4

Quoted 4 lines
.gitlab-ci.yml +3 -0
@@ -1,6 +1,11 @@
 
+stages:
+  - build
+  - update

There is already "stages" section a the beginning of the yml file, so I'd suggest to extend that instead.

Thomas

#4 lore raw
Quoted 15 lines · Thomas Huth
Quoted 14 lines · Paolo Bonzini

Currently, the website is rebuilt on qemu-project.org using an update hook.  We can reuse instead the Jekyll output of GitLab's CI.

To do so, a new user qemu-deploy has been created on qemu.org. The private key is stored into a file variable SSH_PRIVATE_KEY_FILE (be careful to include the trailing newline after "---END OPENSSH PRIVATE KEY---"!).

---
  .gitlab-ci.yml | 28 ++++++++++++++++++++++++++++

  1 file changed, 28 insertions(+)
Quoted 10 lines

.gitlab-ci.yml line 3

Quoted 8 lines
.gitlab-ci.yml +3 -0
index 5fa3041..08b6d20 100644
@@ -1,6 +1,11 @@
+stages:
+  - build
+  - update

There is already "stages" section a the beginning of the yml file, so I'd suggest to extend that instead.

Are you sure? This is the qemu-web CI.

Paolo

#5 lore raw
Quoted 27 lines · Paolo Bonzini
Quoted 15 lines · Thomas Huth
Quoted 14 lines · Paolo Bonzini

Currently, the website is rebuilt on qemu-project.org using an update hook.  We can reuse instead the Jekyll output of GitLab's CI.

To do so, a new user qemu-deploy has been created on qemu.org. The private key is stored into a file variable SSH_PRIVATE_KEY_FILE (be careful to include the trailing newline after "---END OPENSSH PRIVATE KEY---"!).

---
  .gitlab-ci.yml | 28 ++++++++++++++++++++++++++++

  1 file changed, 28 insertions(+)
Quoted 10 lines

.gitlab-ci.yml line 3

Quoted 8 lines
.gitlab-ci.yml +3 -0
index 5fa3041..08b6d20 100644
@@ -1,6 +1,11 @@
+stages:
+  - build
+  - update

There is already "stages" section a the beginning of the yml file, so I'd suggest to extend that instead.

Quoted 1 line

Are you sure?  This is the qemu-web CI.

Never mind, I looked at the wrong yml file :-(

Thomas