From 7da1b0e7985c18c3468fd69e9261e36ad17c1d24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ture=20Gj=C3=B8rup?= Date: Mon, 12 Jun 2023 12:46:33 +0200 Subject: [PATCH 1/9] DISPLAY-986: Updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 977bba5b..2e5e3e20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +- Update docker build ## [1.2.5] - 2023-06-06 From 82ac02d54cb6a59fc9c4877d9a371d8a00c20009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ture=20Gj=C3=B8rup?= Date: Mon, 12 Jun 2023 12:53:19 +0200 Subject: [PATCH 2/9] DISPLAY-986: Update docker build to publish to "os2display" org on docker hup. Update github workflow to latest actions. --- .github/workflows/docker_build_develop.yml | 21 ++++--- .github/workflows/docker_build_tag.yml | 27 +++++---- .github/workflows/github_build_release.yml | 57 +++++++++++++++++++ .../etc/confd/templates/config.tmpl | 2 +- infrastructure/run.sh | 4 +- 5 files changed, 85 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/github_build_release.yml diff --git a/.github/workflows/docker_build_develop.yml b/.github/workflows/docker_build_develop.yml index f1629f6b..39dcd55d 100644 --- a/.github/workflows/docker_build_develop.yml +++ b/.github/workflows/docker_build_develop.yml @@ -14,27 +14,30 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 - - - name: Docker meta - id: meta - uses: docker/metadata-action@v3 - with: - images: itkdev/os2display-client + uses: actions/checkout@v3 - name: Login to DockerHub - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USER }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: os2display/os2display-client + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Set release timestamp run: | echo "APP_RELEASE_TIMESTAMP=$(echo $(date +%s))" >> $GITHUB_ENV echo "APP_RELEASE_TIME=$(echo $(date))" >> $GITHUB_ENV - name: Build and push (API) - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v4 with: context: ./infrastructure/ file: ./infrastructure/Dockerfile diff --git a/.github/workflows/docker_build_tag.yml b/.github/workflows/docker_build_tag.yml index 957c422b..62b4bac5 100644 --- a/.github/workflows/docker_build_tag.yml +++ b/.github/workflows/docker_build_tag.yml @@ -10,37 +10,36 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 - - - name: Docker meta - id: meta - uses: docker/metadata-action@v3 - with: - images: itkdev/os2display-client + uses: actions/checkout@v3 - name: Login to DockerHub - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USER }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: os2display/os2display-client + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Set release timestamp run: | echo "APP_RELEASE_TIMESTAMP=$(echo $(date +%s))" >> $GITHUB_ENV echo "APP_RELEASE_TIME=$(echo $(date))" >> $GITHUB_ENV - - name: Get the tag - id: get_tag - run: echo ::set-output name=git_tag::$(echo $GITHUB_REF_NAME) - - name: Build and push (API) - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v4 with: context: ./infrastructure/ file: ./infrastructure/Dockerfile build-args: | APP_VERSION=${{ github.ref }} - APP_RELEASE_VERSION=${{ steps.get_tag.outputs.git_tag }} + APP_RELEASE_VERSION=$GITHUB_REF_NAME APP_RELEASE_TIMESTAMP=${{ env.APP_RELEASE_TIMESTAMP }} APP_RELEASE_TIME=${{ env.APP_RELEASE_TIME }} push: true diff --git a/.github/workflows/github_build_release.yml b/.github/workflows/github_build_release.yml new file mode 100644 index 00000000..eef90120 --- /dev/null +++ b/.github/workflows/github_build_release.yml @@ -0,0 +1,57 @@ +on: + push: + tags: + - '*.*.*' + +name: Create Github Release + +permissions: + contents: write + +jobs: + create-release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Make build dir + run: | + mkdir -p build + + - name: Build assets + run: | + docker network create frontend + docker compose run --rm node yarn install + docker compose run --rm node yarn build + + - name: Create release file + run: | + rm build/example_release.json + printf "{\n \"releaseTimestamp\": $(date +%s),\n \"releaseTime\": \"$(date)\",\n \"releaseVersion\": \"${{ github.ref_name }}\"\n}" > build/release.json + cat build/release.json + + - name: Rename build dir + # Make archive directory name match expected build "homepage": "/client/", + run: | + mv build/ client + + - name: Make artefacts dir + run: | + mkdir -p ../assets + + - name: Create archive + run: | + tar \ + --exclude ='client/fixtures' \ + -zcf ../assets/${{ github.event.repository.name }}-${{ github.ref_name }}.tar.gz client/* + + - name: Create checksum + run: sha256sum ../assets/${{ github.event.repository.name }}-${{ github.ref_name }}.tar.gz > ../assets/checksum.txt + + - name: Create a release in GitHub and uploads assets + run: | + gh release create ${{ github.ref_name }} --verify-tag --generate-notes ../assets/*.* + env: + GITHUB_TOKEN: ${{ github.TOKEN }} + shell: bash diff --git a/infrastructure/etc/confd/templates/config.tmpl b/infrastructure/etc/confd/templates/config.tmpl index 514b7aa3..df696098 100644 --- a/infrastructure/etc/confd/templates/config.tmpl +++ b/infrastructure/etc/confd/templates/config.tmpl @@ -1,5 +1,5 @@ { - "apiEndpoint": "{{ getenv "APP_API_ENDPOINT" "" }}", + "apiEndpoint": "{{ getenv "APP_API_ENDPOINT" "/" }}", "authenticationEndpoint": "{{ getenv "APP_API_AUTHENTICATION_ENDPOINT" "/v1/authentication/token" }}", "authenticationRefreshTokenEndpoint": "{{ getenv "APP_API_AUTHENTICATION_REFRESH_ENDPOINT" "/v1/authentication/token/refresh" }}", "dataStrategy": { diff --git a/infrastructure/run.sh b/infrastructure/run.sh index 0ed816fd..11072471 100755 --- a/infrastructure/run.sh +++ b/infrastructure/run.sh @@ -7,6 +7,6 @@ APP_RELEASE_TIME=$(date) APP_VERSION=develop VERSION=alpha -docker build --pull --no-cache --build-arg APP_VERSION=${APP_VERSION} --build-arg APP_RELEASE_TIMESTAMP="${APP_RELEASE_TIMESTAMP}" --build-arg APP_RELEASE_TIME="${APP_RELEASE_TIME}" --tag=itkdev/os2display-client:${VERSION} --file="Dockerfile" . +docker build --pull --no-cache --build-arg APP_VERSION=${APP_VERSION} --build-arg APP_RELEASE_TIMESTAMP="${APP_RELEASE_TIMESTAMP}" --build-arg APP_RELEASE_TIME="${APP_RELEASE_TIME}" --tag=os2display/os2display-client:${VERSION} --file="Dockerfile" . -# docker push itkdev/os2display-client:${VERSION} +# docker push os2display/os2display-client:${VERSION} From 05f973e1693e50d1619e8406c02764c4ae2d27b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ture=20Gj=C3=B8rup?= Date: Mon, 12 Jun 2023 12:54:21 +0200 Subject: [PATCH 3/9] DISPLAY-986: Change example_config.json to use relative paths --- public/example_config.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/example_config.json b/public/example_config.json index f67b298c..9d312a0b 100644 --- a/public/example_config.json +++ b/public/example_config.json @@ -1,12 +1,12 @@ { - "apiEndpoint": "https://displayapiservice.local.itkdev.dk", - "authenticationEndpoint": "https://displayapiservice.local.itkdev.dk/v1/authentication/screen", - "authenticationRefreshTokenEndpoint": "https://displayapiservice.local.itkdev.dk/v1/authentication/token/refresh", + "apiEndpoint": "/", + "authenticationEndpoint": "/v1/authentication/screen", + "authenticationRefreshTokenEndpoint": "/v1/authentication/token/refresh", "dataStrategy": { "type": "pull", "config": { "interval": 30000, - "endpoint": "https://displayapiservice.local.itkdev.dk" + "endpoint": "/" } }, "colorScheme": { From 60e1a3eb93419f4c1911f35b488553e11cd03805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ture=20Gj=C3=B8rup?= Date: Mon, 12 Jun 2023 12:54:41 +0200 Subject: [PATCH 4/9] DISPLAY-986: Update Readme with build instructions --- README.md | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c5de8867..f7f2e0f5 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,13 @@ Start docker setup ``` # Install npm packages -docker-compose run node yarn install +docker compose run node yarn install # Up the containers -docker-compose up -d +docker compose up -d # Optional: Follow the node logs to see when the code is compiled. -docker-compose logs -f node +docker compose logs -f node ``` The display client is here: `http://display-client.local.itkdev.dk/`. @@ -34,10 +34,10 @@ For code analysis we use the [Airbnb style guide for javascript](https://github. ``` # Check for coding standards issues -docker-compose exec node bash -c 'yarn check-coding-standards' +docker compose exec node bash -c 'yarn check-coding-standards' # Auto-correct coding standards issues -docker-compose exec node bash -c 'yarn apply-coding-standards' +docker compose exec node bash -c 'yarn apply-coding-standards' ``` ## Testing with cypress @@ -47,11 +47,26 @@ We use [cypress](https://www.cypress.io/) for testing. To run cypress tests in the cypress container: ``` -docker-compose run cypress run +docker compose run cypress run ``` ## Build for production -Builds the app for production to the build folder. +Github actions will build both docker images published to [docker hub](https://hub.docker.com/repository/docker/os2display/os2display-client/general) and release assets published as [github releases](https://github.com/os2display/display-client/releases). To run the display client choose which option suits you and download it. -@TODO: Add production build instructions. +If you wish to do your own production build, you need to do +```shell +docker compose run node yarn install +docker compose run node yarn build + +# Make release file. Replace 'x.y.z' with relevant release version +printf "{\n \"releaseTimestamp\": $(date +%s),\n \"releaseTime\": \"$(date)\",\n \"releaseVersion\": \"x.y.z\"\n}" > build/release.json + +# Make config file +cp public/example_config.json build/config.json +``` + +This will build the client configured to be hosted at `/client`. If you wish to host at a different path +you need to edit `homepage` in `package.json` and re-build. + +For instructions on how to host a complete OS2display setup please see the [docs](https://os2display.github.io/display-docs/). From c4cd7e1eccc0b9eea84f86a30284166a00bbe7e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ture=20Gj=C3=B8rup?= Date: Mon, 12 Jun 2023 12:55:03 +0200 Subject: [PATCH 5/9] DISPLAY-986: Update example_release.json --- public/example_release.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/example_release.json b/public/example_release.json index ffa8d449..51542c3c 100644 --- a/public/example_release.json +++ b/public/example_release.json @@ -1,4 +1,5 @@ { - "releaseTimestamp": 1651175120, + "releaseTimestamp": 1686045152, + "releaseTime": "Tue Jun 6 09:52:32 UTC 2023", "releaseVersion": "1.0.0" } From fb4196fcfb44b866604144c65349fd119f027318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ture=20Gj=C3=B8rup?= Date: Mon, 12 Jun 2023 12:55:13 +0200 Subject: [PATCH 6/9] DISPLAY-986: Update changelog --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e5e3e20..f8206c4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,11 @@ All notable changes to this project will be documented in this file. ## [Unreleased] -- Update docker build +- [#105](https://github.com/os2display/display-client/pull/105) + Update docker build to publish to "os2display" org on docker hup. + Update github workflow to latest actions. + Add github workflow to build and create release. + Change `example_config.json` to use relative paths. ## [1.2.5] - 2023-06-06 From cdc7ca996e714d1d1429ae404914d674c9bcbbe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ture=20Gj=C3=B8rup?= Date: Mon, 12 Jun 2023 13:02:13 +0200 Subject: [PATCH 7/9] DISPLAY-986: Update PR workflow to use latest actions and docker compose --- .github/workflows/pr.yml | 64 +++++++++++++++------------------------- 1 file changed, 24 insertions(+), 40 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 56aef125..47d9ab74 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,52 +1,36 @@ on: pull_request -name: Review +name: Pull Request Review jobs: frontend-build: name: Frontend build runs-on: ubuntu-latest - container: node:14 steps: - - uses: actions/checkout@v2 - - name: Cache node modules - uses: actions/cache@v2 - env: - cache-name: cache-node-modules - with: - path: ~/.yarn - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - - name: install - run: yarn + - name: Checkout + uses: actions/checkout@v3 + + - name: Make build dir + run: | + mkdir -p build - - name: Build production assets - run: yarn build + - name: Build assets + run: | + docker network create frontend + docker compose run --rm node yarn install + docker compose run --rm node yarn build frontend-coding-standards: name: Frontend coding standards runs-on: ubuntu-latest container: node:14 steps: - - uses: actions/checkout@v2 - - - name: Cache node modules - uses: actions/cache@v2 - env: - cache-name: cache-node-modules - with: - path: ~/.yarn - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - - name: install - run: yarn + - name: Checkout + uses: actions/checkout@v3 - name: React coding standards - run: yarn check-coding-standards + run: | + docker network create frontend + docker compose run --rm node yarn install + docker compose run --rm node yarn check-coding-standards cypress: name: Cypress @@ -57,33 +41,33 @@ jobs: browser: ["chrome"] steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup network run: docker network create frontend - name: Install client - run: docker-compose run node yarn + run: docker compose run node yarn - name: Cypress run - run: docker-compose run cypress run --browser ${{ matrix.browser }} + run: docker compose run cypress run --browser ${{ matrix.browser }} - name: Archive screenshots if: ${{ failure() }} uses: actions/upload-artifact@v2 with: - name: cypress-screenhosts-${{ matrix.browser }} + name: cypress-screenshots-${{ matrix.browser }} path: cypress/screenshots retention-days: 7 changelog: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest name: Changelog should be updated strategy: fail-fast: false steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 2 From a43e10aa1c253aa6cf403f382e7c83de112781a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ture=20Gj=C3=B8rup?= Date: Mon, 12 Jun 2023 13:04:48 +0200 Subject: [PATCH 8/9] DISPLAY-986: Removed redundant container from workflow --- .github/workflows/pr.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 47d9ab74..668d3843 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -21,7 +21,6 @@ jobs: frontend-coding-standards: name: Frontend coding standards runs-on: ubuntu-latest - container: node:14 steps: - name: Checkout uses: actions/checkout@v3 From 033f71cd081cc91cff360f05cf3c4ae43ea586bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ture=20Gj=C3=B8rup?= Date: Mon, 12 Jun 2023 15:18:00 +0200 Subject: [PATCH 9/9] DISPLAY-986: Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8206c4c..f1201205 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file. ## [Unreleased] + +## [1.2.6] - 2023-06-12 + - [#105](https://github.com/os2display/display-client/pull/105) Update docker build to publish to "os2display" org on docker hup. Update github workflow to latest actions.