Add job for publishing to netlify

Change-Id: I56707516a00d7b7a2869bde53d025e01cb1376cf
This commit is contained in:
Monty Taylor 2020-07-12 08:46:18 -05:00
parent d6bbcce049
commit 8236df604f
7 changed files with 164 additions and 6 deletions

View File

@ -46,25 +46,102 @@
iodo9pXJsbXDL2xN4uun13sYBy7g/pUf6W2EAGR84BwxezRdLQYeTZy2xhcA+o8nLmmYR
1UJblPsI89YTH8x5rkxLJLBb22LIiNZzWikULd54XpqR9egV5AAwYsainkv+w8=
- secret:
name: inaugust-netlify-auth
data:
token: !encrypted/pkcs1-oaep
- MN4u8YTagu+mZXCbL7SwF0Z1Iee7zuh5m7LhwCzd0ueRVsbVHHbORBVJb+RH3O83bki1h
qD5db5NsIoIgQ4IXvJ/Xc4dG0geTULZfLmDbjPA9l8SW3iraTmYjEIL+qgg+7QWaNFTno
AttKYa3IeJo5A61T6hHz9ijS+5PhKuGwW29Kh/TpFu7HPr+7JRJzhi4n9RAmSYohGiUTM
ZqEmCNVGrU6AQV1CixBli5dwsCSpbYCsA4gohyNSVlHDBnoWAYLGf0kGHisKtJCLeBSpn
lFi7jzm7UYm6UFfjeTUF86C0hyPuK3NtkF3WYv+qUH72DGuYdSVD8daYWlAEZg8ptv+I8
N8tyjrCmCSFjTk8IpLF0B8D9zPAxqnMPGgbB4UI31RDlbxqTZCVRrZzUdmigCkitsOhuA
9d2JVGISif8sAm8mESlni9KXstYst8yFVSS/Y52h8FLp5Ee/CCHa7StQOtI2jaVOOdzdW
mHaRPY91FVGtqw+XDLZbPeaPQlt0Q9XZ7qFB/g0rTtl9eWlQ1KrYjC75LZ7ykqNnm8SNV
0tyrHzRLcignZGyy8LT10x9NGba9r+dToAsVmdHcSzo11WwohRXanzZy6C9/4eeBST+7j
fnFOj7uNfNKo2TpmE3yaFNxDW1RumnlsmR970M0PmUVEVO3owAoAgaJolzTLhA=
- job:
name: inaugust-build-website
parent: build-javascript-content
parent: build-javascript-deployment
success-url: "http://site.{build.uuid}.{tenant.name}.zuul-preview.opendev.org/"
vars:
npm_command: package
node_version: 10
js_build_command: package
javascript_content_dir: dist
- job:
name: inaugust-publish-website
parent: nodejs-npm
parent: build-javascript-deployment
vars:
node_version: 10
npm_command: package
js_build_command: package
javascript_content_dir: dist
post-run: playbooks/publish.yaml
secrets:
- secret: inaugust-secret
name: ssh_key
- job:
name: inaugust-publish-javascript-to-netlify
parent: build-javascript-deployment
description: |
Builds javascript site and deploys to netlify.
Responds to these variables:
.. zuul:jobvar:: js_build_command
:default: build
Command to pass to the javascript package manager..
.. zuul:jobvar:: js_build_tool
:default: autodetected
Command to use for running the package manager, such as npm or yarn.
.. zuul:jobvar:: node_version
:default: 14
The version of Node to use.
.. zuul:jobvar:: zuul_work_dir
:default: {{ zuul.project.src_dir }}
Path to operate in.
.. zuul:jobvar:: javascript_content_dir
:default: public
Directory, relative to zuul_work_dir, holding build content.
.. zuul:jobvar:: netlify_site_id
Site id for the site to publish. This can be found on the site
general settings page as ``API Id``.
.. zuul:rolevar:: netlify_auth
:type: dict
Complex argument which contains the netlify authentication credentials.
This is expected to come from a secret.
.. zuul:rolevar:: token
API token to use to publish the content. Instructions for creating
a token can be found at
https://docs.netlify.com/cli/get-started/#obtain-a-token-in-the-netlify-ui
post-run: playbooks/netlify-publish.yaml
- job:
name: inaugust-publish-netlify
parent: inaugust-publish-javascript-to-netlify
vars:
netlify_site_id: 61580c77-b0fe-42c7-acec-c92d4cd1729c
javascript_content_dir: dist
js_build_command: package
secrets:
- secret: inaugust-netlify-auth
name: netlify_auth
- project:
check:
jobs:
@ -75,3 +152,4 @@
post:
jobs:
- inaugust-publish-website
- inaugust-publish-netlify

View File

@ -0,0 +1,3 @@
- hosts: all
roles:
- netlify-publish

View File

@ -0,0 +1,24 @@
Publish built site to netlify
**Role Variables**
.. zuul:rolevar:: netlify_site_id
Site id for the site to publish. This can be found on the site
general settings page as ``API Id``.
.. zuul:rolevar:: netlify_auth
Complex argument which contains the netlify authentication credentials.
This is expected to come from a secret.
.. zuul:rolevar:: token
API token to use to publish the content. Instructions for creating
a token can be found at
https://docs.netlify.com/cli/get-started/#obtain-a-token-in-the-netlify-ui
.. zuul:rolevar:: zuul_work_dir
:default: {{ zuul.project.src_dir }}
The project directory.

View File

@ -0,0 +1,2 @@
javascript_content_dir: public
zuul_work_dir: "{{ zuul.project.src_dir }}"

View File

@ -0,0 +1,36 @@
- name: Ensure user .netfliy dir
file:
state: directory
mode: 0700
path: "{{ ansible_user_dir }}/.netlify"
- name: Write netlify config file
template:
src: config.json.j2
mode: 0600
dest: "{{ ansible_user_dir }}/.netlify/config.json"
- name: Ensure repo .netfliy dir
file:
state: directory
path: "{{ zuul_work_dir }}/.netlify"
- name: Write repo netlify config file
template:
src: state.json.j2
dest: "{{ zuul_work_dir }}/.netlify/state.json"
- name: Check if netlify cli is installed
stat:
path: "{{ zuul_work_dir }}/node_modules/.bin/netlify"
register: has_netlify_cli
- name: Set netlify cli command
set_fact:
netlify_cli: "{{ has_netlify_cli.stat.exists | ternary('npx netlify', 'npx -p netlify-cli netlify') }}"
- name: Run netlify deployment
command:
cmd: "{{ netlify_cli }} deploy --prod -d {{ javascript_content_dir }}"
chdir: "{{ zuul_work_dir }}"
when: not netlify_publish_skip_upload

View File

@ -0,0 +1,12 @@
{
"telemetryDisabled": false,
"userId": "zuul",
"users": {
"zuul": {
"id": "zuul",
"auth": {
"token": "{{ netlify_auth.token }}"
}
}
}
}

View File

@ -0,0 +1,3 @@
{
"siteId": "{{ netlify_site_id }}"
}