From 825049becef275f221d3727fdf24a084230d87f4 Mon Sep 17 00:00:00 2001 From: Tim Nicholls Date: Wed, 10 May 2023 11:29:11 +0100 Subject: [PATCH] Add GH action to build app and create a release (#9) * Update publish_app.yml Temporarily disable tag filtering * Update publish_app.yml Debug build step * Add missing npm clean install step * Fix eslint warnings in HxtleakEventLog.js so GH action will run * Fix upload artifact step to use path relative to workspace * Add archive creation and tag release * Add zip archive creation to release * Rename release workflow and merge jobs * Fix paths to release artifacts * Set build output and artifact creation to build/app for cleaner deployment path * Update deploy plays to use tagged release of package and install app from release artefacts --- .github/workflows/publish_app.yml | 31 ----------- .github/workflows/release_app.yml | 51 +++++++++++++++++++ control/app/.env.production | 1 + control/app/src/components/HxtleakEventLog.js | 5 +- deploy/ansible/deploy_hxtleak.yml | 11 +++- deploy/ansible/group_vars/hxtleak_bbb.yml | 3 +- deploy/ansible/templates/hxtleak.cfg.j2 | 2 +- 7 files changed, 66 insertions(+), 38 deletions(-) delete mode 100644 .github/workflows/publish_app.yml create mode 100644 .github/workflows/release_app.yml diff --git a/.github/workflows/publish_app.yml b/.github/workflows/publish_app.yml deleted file mode 100644 index da3203c..0000000 --- a/.github/workflows/publish_app.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: publish_app -run-name: Building and publishing static app -on: - push: - tags: - - '*' - -jobs: - build: - runs-on: ubuntu-latest - - defaults: - run: - working-directory: control/app - - strategy: - matrix: - node-version: [16.x] - - steps: - - uses: actions/checkout@v3 - - name: Use node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - - run: npm run build - - name: Save build artifact - uses: actions/upload-artifact@v3 - with: - name: app_build - path: build diff --git a/.github/workflows/release_app.yml b/.github/workflows/release_app.yml new file mode 100644 index 0000000..62b7662 --- /dev/null +++ b/.github/workflows/release_app.yml @@ -0,0 +1,51 @@ +name: release_app +run-name: Build static app and publish with a release +on: + push: + tags: + - '*' + +jobs: + + release: + + runs-on: ubuntu-latest + + defaults: + run: + working-directory: control/app + + strategy: + matrix: + node-version: [16.x] + + steps: + - name: Checkout repo + uses: actions/checkout@v3 + - name: Use node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - name: Clean install app + run: npm ci + - name: Build app + run: npm run build + - name: Create TGZ archive + run: | + cd build + tar -cvzf app_build.tgz app + - name: Create ZIP archive + run: | + cd build + zip -r app_build.zip app + - name: List built files + run: ls -lR build + - name: Create release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: | + control/app/build/app_build.tgz + control/app/build/app_build.zip + + diff --git a/control/app/.env.production b/control/app/.env.production index 79671bb..9539734 100644 --- a/control/app/.env.production +++ b/control/app/.env.production @@ -1 +1,2 @@ REACT_APP_ENDPOINT_URL= +BUILD_PATH=build/app diff --git a/control/app/src/components/HxtleakEventLog.js b/control/app/src/components/HxtleakEventLog.js index 6cdd51d..821383d 100644 --- a/control/app/src/components/HxtleakEventLog.js +++ b/control/app/src/components/HxtleakEventLog.js @@ -1,8 +1,5 @@ import { useState, useEffect, useCallback, useRef } from 'react'; -import Row from 'react-bootstrap/Row'; -import Col from 'react-bootstrap/Col'; - import StatusCard from './StatusCard'; const HxtleakEventLog = ({ endpoint }) => { @@ -35,7 +32,7 @@ const HxtleakEventLog = ({ endpoint }) => { console.log(error.message); }) - }, [events_since, last_timestamp, events]); + }, [events_since, last_timestamp, events]); // eslint-disable-line react-hooks/exhaustive-deps useEffect(() => { let timer_id = null; diff --git a/deploy/ansible/deploy_hxtleak.yml b/deploy/ansible/deploy_hxtleak.yml index 155e559..cfe78c3 100644 --- a/deploy/ansible/deploy_hxtleak.yml +++ b/deploy/ansible/deploy_hxtleak.yml @@ -147,13 +147,22 @@ - name: Install hxtleak package into virtualenv ansible.builtin.pip: - name: "git+{{ hxtleak_repo_url }}#egg=hxtleak&subdirectory=control" + name: "git+{{ hxtleak_repo_url }}.git@{{ hxtleak_release }}#egg=hxtleak&subdirectory=control" virtualenv: "{{ hxt_install_dir}}" editable: yes become: yes become_user: "{{ hxt_user }}" tags: app + - name: Install hxtleak app from Github release + ansible.builtin.unarchive: + src: "{{ hxtleak_repo_url }}/releases/download/{{ hxtleak_release }}/app_build.tgz" + dest: "{{ hxt_install_dir}}" + remote_src: yes + owner: "{{ hxt_user }}" + group: "{{ hxt_group }}" + tags: app + - name: Create config directory for odin-control ansible.builtin.file: path: "{{ hxt_install_dir }}/config" diff --git a/deploy/ansible/group_vars/hxtleak_bbb.yml b/deploy/ansible/group_vars/hxtleak_bbb.yml index 95f4659..4b0a990 100644 --- a/deploy/ansible/group_vars/hxtleak_bbb.yml +++ b/deploy/ansible/group_vars/hxtleak_bbb.yml @@ -5,4 +5,5 @@ hxt_group: hexitec hxt_user: hexiuser hxt_sw_dir: /hxt_sw hxt_install_dir: "{{ hxt_sw_dir }}/install" -hxtleak_repo_url: https://github.com/stfc-aeg/hxtleak.git +hxtleak_repo_url: https://github.com/stfc-aeg/hxtleak +hxtleak_release: "0.1.1" diff --git a/deploy/ansible/templates/hxtleak.cfg.j2 b/deploy/ansible/templates/hxtleak.cfg.j2 index 40aeda7..a378fa1 100644 --- a/deploy/ansible/templates/hxtleak.cfg.j2 +++ b/deploy/ansible/templates/hxtleak.cfg.j2 @@ -2,7 +2,7 @@ debug_mode = 1 http_port = 80 http_addr = 0.0.0.0 -static_path = {{ hxt_install_dir }}/static +static_path = {{ hxt_install_dir }}/app adapters = hxtleak enable_cors = true