Skip to content

Commit d9a27af

Browse files
authored
Merge pull request #15 from paul-gilber/finishing-touches
Update workflows, docs, and release notes
2 parents 1f8a634 + c65d93b commit d9a27af

File tree

13 files changed

+346
-164
lines changed

13 files changed

+346
-164
lines changed

.githooks/pre-commit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22

33
# Lint YAML Files
44
yamllint .
5+
6+
# Dry-run docker compose
7+
docker compose --project-directory deploy/docker-compose create --dry-run

.github/release-drafter.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,14 @@ template: |
4141
4242
## Install from the command line
4343
```sh
44-
DEMOAPP_FRONTEND_IMAGE="ghcr.io/$OWNER/$REPOSITORY:v$RESOLVED_VERSION" docker compose --project-directory deploy/docker-compose up
44+
DEMOAPP_FRONTEND_IMAGE="ghcr.io/$OWNER/$REPOSITORY:v$RESOLVED_VERSION" \
45+
DEMOAPP_BACKEND_IMAGE="ghcr.io/paul-gilber/demoapp-backend:latest" \
46+
MYSQL_IMAGE="mysql:8.0" \
47+
docker compose --project-directory deploy/docker-compose up
48+
# Application URL: http://localhost:8080/
49+
```
50+
51+
## Uninstall from the command line
52+
```sh
53+
docker compose --project-directory deploy/docker-compose down --volumes
4554
```

.github/workflows/build.yml

Lines changed: 33 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,43 @@ concurrency:
2828
group: ${{ github.workflow }}-${{ github.ref }}
2929
cancel-in-progress: true
3030

31-
# Set Workflow-level environment variables
32-
env:
33-
PROJECT: demoapp-frontend
34-
3531
jobs:
36-
build:
32+
unit-test:
3733
# Run job when not triggered by a merge
3834
if: (github.event_name == 'push' && contains(toJSON(github.event.head_commit.message), 'Merge pull request ') == false) || (github.event_name != 'push')
3935
runs-on: ubuntu-latest
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v4 # https://github.com/marketplace/actions/checkout
39+
40+
# Cache NPM dependencies
41+
- name: Cache NPM dependencies
42+
id: cache
43+
uses: actions/cache@v3 # https://github.com/marketplace/actions/cache#using-a-combination-of-restore-and-save-actions
44+
with:
45+
path: |
46+
node_modules
47+
key: npm-${{ hashFiles('package-lock.json') }}
48+
49+
# Install NPM dependencies
50+
- name: Install NPM dependencies
51+
run: npm ci
52+
53+
- name: Run tests
54+
run: npm run test
55+
56+
build:
57+
needs: unit-test
58+
runs-on: ubuntu-latest
4059
environment: docker-hub # Use `docker-hub` repository environment
41-
# Uncomment lines below to run `build` job on container
42-
# Note: container image must contains commands required for step execution, e.g. docker, gzip, etc.
43-
# container:
44-
# image: mcr.microsoft.com/openjdk/jdk:17-ubuntu # Image Java version must match with `project.version` in pom.xml
45-
# # Set credentials when container registry requires authentication to pull the image
46-
# # credentials:
47-
# # username: ${{ github.actor }}
48-
# # password: ${{ secrets.github_token }}
4960
steps:
50-
# Workaround for the absence of github.branch_name
51-
# Setting an environment variable: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
52-
- name: Set VERSION
53-
if: github.head_ref != ''
54-
run: |
55-
echo "VERSION=${{ github.head_ref }}" >> $GITHUB_ENV
56-
- name: Set VERSION
57-
if: github.head_ref == ''
58-
run: |
59-
echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
61+
# Workaround for the absence of github.branch_name, use github-env-vars-action to define useful environment variables not available by default
62+
- uses: FranzDiebold/github-env-vars-action@v2 # https://github.com/marketplace/actions/github-environment-variables-action
6063

6164
# Set Complete Container Image URL
6265
- name: Set CONTAINER_IMAGE_URL
6366
run: |
64-
echo "CONTAINER_IMAGE_URL=${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.PROJECT }}:${{ env.VERSION }}" >> $GITHUB_ENV
67+
echo "CONTAINER_IMAGE_URL=${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.CI_REPOSITORY_NAME }}:${{ env.CI_ACTION_REF_NAME }}" >> $GITHUB_ENV
6568
6669
- name: Checkout repository
6770
uses: actions/checkout@v4 # https://github.com/marketplace/actions/checkout
@@ -91,21 +94,13 @@ jobs:
9194
runs-on: ubuntu-latest
9295
environment: docker-hub # Use `docker-hub` repository environment
9396
steps:
94-
# Workaround for the absence of github.branch_name
95-
# Setting an environment variable: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
96-
- name: Set VERSION
97-
if: github.head_ref != ''
98-
run: |
99-
echo "VERSION=${{ github.head_ref }}" >> $GITHUB_ENV
100-
- name: Set VERSION
101-
if: github.head_ref == ''
102-
run: |
103-
echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
97+
# Workaround for the absence of github.branch_name, use github-env-vars-action to define useful environment variables not available by default
98+
- uses: FranzDiebold/github-env-vars-action@v2 # https://github.com/marketplace/actions/github-environment-variables-action
10499

105100
# Set Complete Container Image URL
106101
- name: Set CONTAINER_IMAGE_URL
107102
run: |
108-
echo "CONTAINER_IMAGE_URL=${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.PROJECT }}:${{ env.VERSION }}" >> $GITHUB_ENV
103+
echo "CONTAINER_IMAGE_URL=${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.CI_REPOSITORY_NAME }}:${{ env.CI_ACTION_REF_NAME }}" >> $GITHUB_ENV
109104
110105
- name: Login to DockerHub
111106
uses: docker/login-action@v3 # https://github.com/marketplace/actions/docker-login
@@ -137,21 +132,13 @@ jobs:
137132
env:
138133
TRIVY_CACHE_DIR: /tmp/trivy/
139134
steps:
140-
# Workaround for the absence of github.branch_name
141-
# Setting an environment variable: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
142-
- name: Set VERSION
143-
if: github.head_ref != ''
144-
run: |
145-
echo "VERSION=${{ github.head_ref }}" >> $GITHUB_ENV
146-
- name: Set VERSION
147-
if: github.head_ref == ''
148-
run: |
149-
echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
135+
# Workaround for the absence of github.branch_name, use github-env-vars-action to define useful environment variables not available by default
136+
- uses: FranzDiebold/github-env-vars-action@v2 # https://github.com/marketplace/actions/github-environment-variables-action
150137

151138
# Set Complete Container Image URL
152139
- name: Set CONTAINER_IMAGE_URL
153140
run: |
154-
echo "CONTAINER_IMAGE_URL=${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.PROJECT }}:${{ env.VERSION }}" >> $GITHUB_ENV
141+
echo "CONTAINER_IMAGE_URL=${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.CI_REPOSITORY_NAME }}:${{ env.CI_ACTION_REF_NAME }}" >> $GITHUB_ENV
155142
156143
- name: Checkout repository
157144
uses: actions/checkout@v4 # https://github.com/marketplace/actions/checkout

.github/workflows/code-scan-sonarcloud.yml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,8 @@ jobs:
3333
pull-requests: read # Allow SonarCloud to get pull request details
3434
environment: sonarcloud # Use `sonarcloud` repository environment
3535
steps:
36-
# Workaround for the absence of github.branch_name
37-
# Setting an environment variable: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
38-
- name: Set VERSION
39-
if: github.head_ref != ''
40-
run: |
41-
echo "VERSION=${{ github.head_ref }}" >> $GITHUB_ENV
42-
- name: Set VERSION
43-
if: github.head_ref == ''
44-
run: |
45-
echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
36+
# Workaround for the absence of github.branch_name, use github-env-vars-action to define useful environment variables not available by default
37+
- uses: FranzDiebold/github-env-vars-action@v2 # https://github.com/marketplace/actions/github-environment-variables-action
4638

4739
- name: Checkout repository
4840
uses: actions/checkout@v4 # https://github.com/marketplace/actions/checkout
@@ -65,8 +57,8 @@ jobs:
6557
with:
6658
projectBaseDir: src
6759
args: >
68-
-Dsonar.organization=${{ vars.SONAR_ORGANIZATION }}
69-
-Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY }}
60+
-Dsonar.organization=${{ env.CI_REPOSITORY_OWNER }}
61+
-Dsonar.projectKey=${{ env.CI_REPOSITORY_OWNER }}_${{ env.CI_REPOSITORY_NAME }}
7062
7163
# In case you need to override default settings
7264
# - name: Analyze with SonarCloud
@@ -91,7 +83,7 @@ jobs:
9183
# run: |
9284
# mvn -B verify \
9385
# org.sonarsource.scanner.npm:sonar-npm-plugin:sonar \
94-
# -Drevision=${{ env.VERSION }} \
86+
# -Drevision=${{ env.CI_ACTION_REF_NAME }} \
9587
# -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }} \
9688
# -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY }} \
9789
# -Dmaven.test.skip=true \
@@ -111,7 +103,7 @@ jobs:
111103
# run: |
112104
# mvn -B verify \
113105
# org.sonarsource.scanner.npm:sonar-npm-plugin:sonar \
114-
# -Drevision=${{ env.VERSION }} \
106+
# -Drevision=${{ env.CI_ACTION_REF_NAME }} \
115107
# -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }} \
116108
# -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY }} \
117109
# -Dsonar.pullrequest.provider=GitHub \

.github/workflows/merge-cleanup.yml

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ on:
2020
# Set Workflow-level permissions: https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
2121
permissions: {} # This Workflow does not require any permission
2222

23-
# Set Workflow-level environment variables
24-
env:
25-
PROJECT: demoapp-frontend
26-
2723
jobs:
2824
output-information:
2925
runs-on: ubuntu-latest
@@ -45,23 +41,20 @@ jobs:
4541
# - name: Skopeo Delete Image
4642
# id: skopeo-delete
4743
# run: |
48-
# skopeo delete docker://${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.PROJECT }}:${{ env.VERSION }}
44+
# skopeo delete docker://${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.CI_REPOSITORY_NAME }}:${{ env.CI_ACTION_REF_NAME }}
4945

5046
# Regctl allows image tag deletion which is allowed by Docker Hub
5147
docker-hub-regctl:
5248
runs-on: ubuntu-latest
5349
environment: docker-hub
5450
steps:
55-
# Workaround for the absence of github.branch_name
56-
# Setting an environment variable: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
57-
- name: Set VERSION
58-
if: github.head_ref != ''
59-
run: |
60-
echo "VERSION=${{ github.head_ref }}" >> $GITHUB_ENV
61-
- name: Set VERSION
62-
if: github.head_ref == ''
51+
# Workaround for the absence of github.branch_name, use github-env-vars-action to define useful environment variables not available by default
52+
- uses: FranzDiebold/github-env-vars-action@v2 # https://github.com/marketplace/actions/github-environment-variables-action
53+
54+
# Set Complete Container Image URL
55+
- name: Set CONTAINER_IMAGE_URL
6356
run: |
64-
echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
57+
echo "CONTAINER_IMAGE_URL=${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.CI_REPOSITORY_NAME }}:${{ env.CI_ACTION_REF_NAME }}" >> $GITHUB_ENV
6558
6659
# Install regctl: https://github.com/regclient/regclient
6760
- name: Install regctl
@@ -75,4 +68,4 @@ jobs:
7568
--pass ${{ secrets.DOCKER_REGISTRY_PASSWORD }} \
7669
- name: regctl Delete Image Tag
7770
run: |
78-
./regctl tag delete ${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.PROJECT }}:${{ env.VERSION }}
71+
./regctl tag delete ${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.CI_REPOSITORY_NAME }}:${{ env.CI_ACTION_REF_NAME }}

.github/workflows/release.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ on:
1212
tags:
1313
- 'v*' # When a tag starting with `v` is created e.g. v1.0.0
1414

15-
# Set Workflow-level environment variables
16-
env:
17-
PROJECT: demoapp-frontend
18-
1915
jobs:
2016
push_to_registries:
2117
name: Push Container image to multiple registries

Containerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ ARG RUNTIME_IMAGE="registry.access.redhat.com/ubi8/nodejs-18"
55
FROM ${BUILD_IMAGE} as build
66
WORKDIR /build
77

8+
COPY package-lock.json ./package-lock.json
89
COPY package.json ./package.json
910
COPY public ./public
1011
COPY src ./src
1112

12-
RUN npm install \
13+
RUN npm ci \
1314
&& npm run build
1415

1516

0 commit comments

Comments
 (0)