From 18facb03c60a685b5a862a0f6c267ab16bf41231 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Fri, 29 Sep 2023 08:02:56 +0300 Subject: [PATCH 1/6] release: copy cloudflare assets when promoting --- .../www-standalone/tools/promote/_promote.sh | 1 + .../tools/promote/promote_release.sh | 2 ++ ansible/www-standalone/tools/promote/settings | 4 ++++ .../tools/promote/upload_to_cloudflare.sh | 20 +++++++++++++++++++ 4 files changed, 27 insertions(+) create mode 100755 ansible/www-standalone/tools/promote/upload_to_cloudflare.sh diff --git a/ansible/www-standalone/tools/promote/_promote.sh b/ansible/www-standalone/tools/promote/_promote.sh index 6443564b4..37b602b95 100755 --- a/ansible/www-standalone/tools/promote/_promote.sh +++ b/ansible/www-standalone/tools/promote/_promote.sh @@ -46,6 +46,7 @@ for subdir in $(cd $srcdir && ls); do fi rm -f "${srcdir}/${subdir}/${donefile}" + . ${__dirname}/upload_to_cloudflare.sh $site $subdir done diff --git a/ansible/www-standalone/tools/promote/promote_release.sh b/ansible/www-standalone/tools/promote/promote_release.sh index f720985f9..947c86e50 100755 --- a/ansible/www-standalone/tools/promote/promote_release.sh +++ b/ansible/www-standalone/tools/promote/promote_release.sh @@ -37,6 +37,8 @@ while true; do if [ "X${yorn}" == "Xy" ]; then . ${__dirname}/_promote.sh $site $2 nodejs-latest-linker /home/dist/${site}/release/ /home/dist/${site}/docs/ + dstdir=/home/dist/${site}/docs + . ${__dirname}/upload_to_cloudflare.sh $site $2 break fi done diff --git a/ansible/www-standalone/tools/promote/settings b/ansible/www-standalone/tools/promote/settings index 3ce9bc811..17ddd827a 100755 --- a/ansible/www-standalone/tools/promote/settings +++ b/ansible/www-standalone/tools/promote/settings @@ -36,3 +36,7 @@ chakracore_rc_dirmatch=.* chakracore_release_srcdir=${staging_rootdir}chakracore-release chakracore_release_dstdir=${dist_rootdir}chakracore-release chakracore_release_dirmatch=.* + +cloudflare_endpoint=https://07be8d2fbc940503ca1be344714cb0d1.r2.cloudflarestorage.com +cloudflare_profile=worker +destination_bucket=s3://dist-prod diff --git a/ansible/www-standalone/tools/promote/upload_to_cloudflare.sh b/ansible/www-standalone/tools/promote/upload_to_cloudflare.sh new file mode 100755 index 000000000..5f482ffde --- /dev/null +++ b/ansible/www-standalone/tools/promote/upload_to_cloudflare.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -e + +site=$1 + +if [ "X$site" != "Xiojs" ] && [ "X$site" != "Xnodejs" ]; then + echo "Usage: upload_to_cloudflare.sh < iojs | nodejs > " + exit 1 +fi + +if [ "X$2" == "X" ]; then + echo "Usage: upload_to_cloudflare.sh < iojs | nodejs > " + exit 1 +fi + +relativedir=${dstdir/$dist_rootdir/"$site/"} +version=$2 + +aws s3 cp $dstdir/$version/ $destination_bucket/$relativedir/$version/ --endpoint-url=$cloudflare_endpoint --profile $cloudflare_profile --recursive From cc38eaeeaa551a3e9c9f111b49a21fdea9bb4dd0 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Sat, 30 Sep 2023 21:33:52 +0300 Subject: [PATCH 2/6] CR --- ansible/www-standalone/ansible-playbook.yaml | 3 ++ ansible/www-standalone/tasks/cloufdflare.yaml | 45 +++++++++++++++++++ .../tools/promote/upload_to_cloudflare.sh | 21 +++++++++ 3 files changed, 69 insertions(+) create mode 100644 ansible/www-standalone/tasks/cloufdflare.yaml diff --git a/ansible/www-standalone/ansible-playbook.yaml b/ansible/www-standalone/ansible-playbook.yaml index f97b0955d..a9e67ba1f 100644 --- a/ansible/www-standalone/ansible-playbook.yaml +++ b/ansible/www-standalone/ansible-playbook.yaml @@ -32,3 +32,6 @@ - include: tasks/metrics.yaml tags: metrics + + - include: tasks/cloudflare.yaml + tags: cloudflare diff --git a/ansible/www-standalone/tasks/cloufdflare.yaml b/ansible/www-standalone/tasks/cloufdflare.yaml new file mode 100644 index 000000000..f5dc56523 --- /dev/null +++ b/ansible/www-standalone/tasks/cloufdflare.yaml @@ -0,0 +1,45 @@ +--- + +- name: create .aws directory + ansible.builtin.file: + dest: "dist/.aws" + owner: dist + group: dist + state: directory + +- name: copy credentials to deploy release artifacts + ansible.builtin.copy: + content: "{{ secrets.worker_credentials }}" + dest: "dist/.aws/credentials" + owner: dist + group: dist + +- name: write worker_config + ansible.builtin.copy: + dest: "dist/.aws/config" + src: "{{ role_path }}/files/worker_config" + owner: dist + group: dist + + +# https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html +- name: Download awscliv2 installer + unarchive: + src: "https://awscli.amazonaws.com/awscli-exe-linux-{{ ansible_architecture }}.zip" + dest: "/tmp" + remote_src: true + creates: '/tmp/aws' + mode: 0755 + +- name: Run awscliv2 installer + command: + args: + cmd: "/tmp/aws/install" + creates: /usr/local/bin/aws + become: true + register: aws_install + +- name: "Show awscliv2 installer output" + debug: + var: aws_install + verbosity: 2 diff --git a/ansible/www-standalone/tools/promote/upload_to_cloudflare.sh b/ansible/www-standalone/tools/promote/upload_to_cloudflare.sh index 5f482ffde..55cdeb262 100755 --- a/ansible/www-standalone/tools/promote/upload_to_cloudflare.sh +++ b/ansible/www-standalone/tools/promote/upload_to_cloudflare.sh @@ -14,6 +14,27 @@ if [ "X$2" == "X" ]; then exit 1 fi +if [ -z ${dstdir+x} ]; then + echo "\$dstdir is not set" + exit 1 +fi +if [ -z ${dist_rootdir+x} ]; then + echo "\$dist_rootdir is not set" + exit 1 +fi +if [ -z ${destination_bucket+x} ]; then + echo "\$destination_bucket is not set" + exit 1 +fi +if [ -z ${cloudflare_endpoint+x} ]; then + echo "\$cloudflare_endpoint is not set" + exit 1 +fi +if [ -z ${cloudflare_profile+x} ]; then + echo "\$cloudflare_profile is not set" + exit 1 +fi + relativedir=${dstdir/$dist_rootdir/"$site/"} version=$2 From a2d5320b35c85c778ad2603b164bf01a2d322267 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Sun, 1 Oct 2023 09:59:40 +0300 Subject: [PATCH 3/6] more --- ansible/www-standalone/tools/promote/_promote.sh | 3 ++- ansible/www-standalone/tools/promote/promote_release.sh | 2 -- ansible/www-standalone/tools/promote/resha_release.sh | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ansible/www-standalone/tools/promote/_promote.sh b/ansible/www-standalone/tools/promote/_promote.sh index 37b602b95..5e54178c4 100755 --- a/ansible/www-standalone/tools/promote/_promote.sh +++ b/ansible/www-standalone/tools/promote/_promote.sh @@ -46,7 +46,6 @@ for subdir in $(cd $srcdir && ls); do fi rm -f "${srcdir}/${subdir}/${donefile}" - . ${__dirname}/upload_to_cloudflare.sh $site $subdir done @@ -54,6 +53,8 @@ for subdir in $(cd $srcdir && ls); do ${__dirname}/_resha.sh $site $dstdir $subdir fi + . ${__dirname}/upload_to_cloudflare.sh $site $subdir + fi done diff --git a/ansible/www-standalone/tools/promote/promote_release.sh b/ansible/www-standalone/tools/promote/promote_release.sh index 947c86e50..f720985f9 100755 --- a/ansible/www-standalone/tools/promote/promote_release.sh +++ b/ansible/www-standalone/tools/promote/promote_release.sh @@ -37,8 +37,6 @@ while true; do if [ "X${yorn}" == "Xy" ]; then . ${__dirname}/_promote.sh $site $2 nodejs-latest-linker /home/dist/${site}/release/ /home/dist/${site}/docs/ - dstdir=/home/dist/${site}/docs - . ${__dirname}/upload_to_cloudflare.sh $site $2 break fi done diff --git a/ansible/www-standalone/tools/promote/resha_release.sh b/ansible/www-standalone/tools/promote/resha_release.sh index 8bd6f4a1f..86fd92694 100755 --- a/ansible/www-standalone/tools/promote/resha_release.sh +++ b/ansible/www-standalone/tools/promote/resha_release.sh @@ -25,4 +25,6 @@ fi ${__dirname}/_resha.sh $site $dstdir $2 +. ${__dirname}/upload_to_cloudflare.sh $site $2 + /home/nodejs/queue-cdn-purge.sh $site resha_release From a3a6facfe312fa89118cacee90980fd2b31e7a73 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Sun, 1 Oct 2023 15:44:13 +0300 Subject: [PATCH 4/6] fixes --- ansible/www-standalone/tools/promote/_promote.sh | 3 +-- ansible/www-standalone/tools/promote/upload_to_cloudflare.sh | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/ansible/www-standalone/tools/promote/_promote.sh b/ansible/www-standalone/tools/promote/_promote.sh index 5e54178c4..3001a0cf6 100755 --- a/ansible/www-standalone/tools/promote/_promote.sh +++ b/ansible/www-standalone/tools/promote/_promote.sh @@ -51,9 +51,8 @@ for subdir in $(cd $srcdir && ls); do if [ "X${version}" == "X" ] && [ "$resha" == "yes" ]; then ${__dirname}/_resha.sh $site $dstdir $subdir - fi - . ${__dirname}/upload_to_cloudflare.sh $site $subdir + fi fi diff --git a/ansible/www-standalone/tools/promote/upload_to_cloudflare.sh b/ansible/www-standalone/tools/promote/upload_to_cloudflare.sh index 55cdeb262..ef80b57da 100755 --- a/ansible/www-standalone/tools/promote/upload_to_cloudflare.sh +++ b/ansible/www-standalone/tools/promote/upload_to_cloudflare.sh @@ -36,6 +36,6 @@ if [ -z ${cloudflare_profile+x} ]; then fi relativedir=${dstdir/$dist_rootdir/"$site/"} -version=$2 +tmpversion=$2 -aws s3 cp $dstdir/$version/ $destination_bucket/$relativedir/$version/ --endpoint-url=$cloudflare_endpoint --profile $cloudflare_profile --recursive +aws s3 cp $dstdir/$tmpversion/ $destination_bucket/$relativedir/$tmpversion/ --endpoint-url=$cloudflare_endpoint --profile $cloudflare_profile --recursive From a4468ff6b3d31de1a750e9a6120dcf4c9fdd5522 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Mon, 2 Oct 2023 10:11:56 +0300 Subject: [PATCH 5/6] add index files --- ansible/www-standalone/tools/promote/upload_to_cloudflare.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ansible/www-standalone/tools/promote/upload_to_cloudflare.sh b/ansible/www-standalone/tools/promote/upload_to_cloudflare.sh index ef80b57da..aaa98507d 100755 --- a/ansible/www-standalone/tools/promote/upload_to_cloudflare.sh +++ b/ansible/www-standalone/tools/promote/upload_to_cloudflare.sh @@ -39,3 +39,5 @@ relativedir=${dstdir/$dist_rootdir/"$site/"} tmpversion=$2 aws s3 cp $dstdir/$tmpversion/ $destination_bucket/$relativedir/$tmpversion/ --endpoint-url=$cloudflare_endpoint --profile $cloudflare_profile --recursive +aws s3 cp $dstdir/index.json $destination_bucket/index.json --endpoint-url=$cloudflare_endpoint --profile $cloudflare_profile --recursive +aws s3 cp $dstdir/index.tab $destination_bucket/index.tab --endpoint-url=$cloudflare_endpoint --profile $cloudflare_profile --recursive From 6d6d76fe701d61379ae84dbfebbd9a4102a0e535 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Mon, 2 Oct 2023 10:25:34 +0300 Subject: [PATCH 6/6] fix --- ansible/www-standalone/tools/promote/upload_to_cloudflare.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ansible/www-standalone/tools/promote/upload_to_cloudflare.sh b/ansible/www-standalone/tools/promote/upload_to_cloudflare.sh index aaa98507d..4fdec7f1f 100755 --- a/ansible/www-standalone/tools/promote/upload_to_cloudflare.sh +++ b/ansible/www-standalone/tools/promote/upload_to_cloudflare.sh @@ -39,5 +39,5 @@ relativedir=${dstdir/$dist_rootdir/"$site/"} tmpversion=$2 aws s3 cp $dstdir/$tmpversion/ $destination_bucket/$relativedir/$tmpversion/ --endpoint-url=$cloudflare_endpoint --profile $cloudflare_profile --recursive -aws s3 cp $dstdir/index.json $destination_bucket/index.json --endpoint-url=$cloudflare_endpoint --profile $cloudflare_profile --recursive -aws s3 cp $dstdir/index.tab $destination_bucket/index.tab --endpoint-url=$cloudflare_endpoint --profile $cloudflare_profile --recursive +aws s3 cp $dstdir/index.json $destination_bucket/$relativedir/index.json --endpoint-url=$cloudflare_endpoint --profile $cloudflare_profile +aws s3 cp $dstdir/index.tab $destination_bucket/$relativedir/index.tab --endpoint-url=$cloudflare_endpoint --profile $cloudflare_profile