Skip to content

Commit

Permalink
release: copy cloudflare assets when promoting (#3505)
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow authored Oct 2, 2023
1 parent 726a7ca commit b8b63ad
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ansible/www-standalone/ansible-playbook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@

- include: tasks/metrics.yaml
tags: metrics

- include: tasks/cloudflare.yaml
tags: cloudflare
45 changes: 45 additions & 0 deletions ansible/www-standalone/tasks/cloufdflare.yaml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions ansible/www-standalone/tools/promote/_promote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ for subdir in $(cd $srcdir && ls); do

if [ "X${version}" == "X" ] && [ "$resha" == "yes" ]; then
${__dirname}/_resha.sh $site $dstdir $subdir
. ${__dirname}/upload_to_cloudflare.sh $site $subdir
fi

fi
Expand Down
2 changes: 2 additions & 0 deletions ansible/www-standalone/tools/promote/resha_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions ansible/www-standalone/tools/promote/settings
Original file line number Diff line number Diff line change
Expand Up @@ -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
43 changes: 43 additions & 0 deletions ansible/www-standalone/tools/promote/upload_to_cloudflare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

set -e

site=$1

if [ "X$site" != "Xiojs" ] && [ "X$site" != "Xnodejs" ]; then
echo "Usage: upload_to_cloudflare.sh < iojs | nodejs > <version>"
exit 1
fi

if [ "X$2" == "X" ]; then
echo "Usage: upload_to_cloudflare.sh < iojs | nodejs > <version>"
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/"}
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/$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

0 comments on commit b8b63ad

Please sign in to comment.