-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69c0397
commit b7fc084
Showing
5 changed files
with
360 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
# | ||
# This source file is part of the Stanford Biodesign Digital Health Group open-source organization | ||
# Based on the Apodini workflow found at: https://github.com/Apodini/.github/workflows/docker-build-and-push.yml | ||
# and the docker documentation found at https://docs.docker.com/build/ci/github-actions/multi-platform/ | ||
# | ||
# SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
|
||
|
||
name: Docker Build and Push | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
dockerFile: | ||
description: 'Path or name of the Docker file. The default values is `Dockerfile`. The docker file can use the `baseimage` to get an architecture specific Swift base image' | ||
required: false | ||
type: string | ||
default: 'Dockerfile' | ||
imageName: | ||
description: 'The name used to tag the docker image on the defined registry containing the organzation/account name and the name of the image, e.g.: stanfordbdhg/example' | ||
required: true | ||
type: string | ||
registry: | ||
description: 'Server address of Docker registry. If not set then will default to ghcr.io' | ||
required: false | ||
type: string | ||
default: 'ghcr.io' | ||
workingDirectory: | ||
description: 'The working-directory of the GitHub Action. Defaults to $GITHUB_WORKSPACE' | ||
required: false | ||
type: string | ||
default: '.' | ||
secrets: | ||
username: | ||
description: 'Username for authenticating to the Docker registry. Uses the GitHub actor by default.' | ||
required: false | ||
password: | ||
description: 'Password or personal access token for authenticating the Docker registry. Uses the GitHub token by default.' | ||
required: false | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ${{ inputs.workingDirectory }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
platform: | ||
- linux/amd64 | ||
- linux/arm64 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ inputs.imageName }} | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Setup Credentials | ||
id: credentials | ||
run: | | ||
USERNAME=${{ secrets.username }} | ||
PASSWORD=${{ secrets.password }} | ||
if [ -z "$USERNAME" ]; then | ||
USERNAME=${{ github.actor }} | ||
fi | ||
if [ -z "$PASSWORD" ]; then | ||
PASSWORD=${{ secrets.GITHUB_TOKEN }} | ||
fi | ||
echo "username=$USERNAME" >> "$GITHUB_OUTPUT" | ||
echo "password=$PASSWORD" >> "$GITHUB_OUTPUT" | ||
- name: Log in to ${{ inputs.registry }} | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ inputs.registry }} | ||
username: ${{ steps.credentials.outputs.username }} | ||
password: ${{ steps.credentials.outputs.password }} | ||
- name: Build and push by digest | ||
id: build | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: ${{ inputs.dockerFile }} | ||
platforms: ${{ matrix.platform }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
outputs: type=image,name=${{ inputs.registry }}/${{ inputs.imageName }},push-by-digest=true,name-canonical=true,push=true | ||
- name: Export digest | ||
run: | | ||
mkdir -p /tmp/digests | ||
digest="${{ steps.build.outputs.digest }}" | ||
touch "/tmp/digests/${digest#sha256:}" | ||
- name: Upload digest | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: digests | ||
path: /tmp/digests/* | ||
if-no-files-found: error | ||
retention-days: 1 | ||
merge: | ||
runs-on: ubuntu-latest | ||
needs: | ||
- build | ||
steps: | ||
- name: Download digests | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: digests | ||
path: /tmp/digests | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ inputs.imageName }} | ||
- name: Setup Credentials | ||
id: credentials | ||
run: | | ||
USERNAME=${{ secrets.username }} | ||
PASSWORD=${{ secrets.password }} | ||
if [ -z "$USERNAME" ]; then | ||
USERNAME=${{ github.actor }} | ||
fi | ||
if [ -z "$PASSWORD" ]; then | ||
PASSWORD=${{ secrets.GITHUB_TOKEN }} | ||
fi | ||
echo "username=$USERNAME" >> "$GITHUB_OUTPUT" | ||
echo "password=$PASSWORD" >> "$GITHUB_OUTPUT" | ||
- name: Log in to ${{ inputs.registry }} | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ inputs.registry }} | ||
username: ${{ steps.credentials.outputs.username }} | ||
password: ${{ steps.credentials.outputs.password }} | ||
- name: Create manifest list and push | ||
working-directory: /tmp/digests | ||
run: | | ||
docker buildx imagetools create $(jq -cr '.tags | map("-t ${{ inputs.registry }}/" + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | ||
$(printf '${{ inputs.registry }}/${{ inputs.imageName }}@sha256:%s ' *) | ||
- name: Inspect image | ||
run: | | ||
docker buildx imagetools inspect ${{ inputs.registry }}/${{ inputs.imageName }}:${{ steps.meta.outputs.version }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# | ||
# This source file is part of the Stanford Biodesign Digital Health Group open-source organization | ||
# Based on the Apodini workflow found at: https://github.com/Apodini/.github/workflows/docker-compose-test.yml | ||
# | ||
# SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
|
||
name: Docker Compose | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
dockerComposeFile: | ||
description: 'Path or name of the Docker compose file. The default values is `docker-compose.yml`' | ||
required: false | ||
type: string | ||
default: 'docker-compose.yml' | ||
workingDirectory: | ||
description: 'The workingDirectory of the GitHub Action. Defaults to $GITHUB_WORKSPACE' | ||
required: false | ||
type: string | ||
default: '.' | ||
testscript: | ||
description: 'Optional path or name to a test script to test the Docker compose setup' | ||
required: false | ||
type: string | ||
|
||
jobs: | ||
buildandtest: | ||
name: Build and Test | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ${{ inputs.workingDirectory }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Docker compose up | ||
run: docker-compose -f ${{ inputs.workingDirectory }}/${{ inputs.dockerComposeFile }} up -d --build | ||
- name: Run test script | ||
if: inputs.testscript != '' | ||
run: | | ||
sleep 5 | ||
sh ${{ inputs.testscript }} | ||
- name: Docker compose down | ||
if: always() | ||
run: docker-compose down |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# | ||
# This source file is part of the Stanford Biodesign Digital Health Group open-source organization | ||
# | ||
# SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
|
||
name: ESLint | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
nodeVersion: | ||
description: 'Node version spec of the version to use in SemVer notation.' | ||
required: false | ||
type: string | ||
default: '18' | ||
|
||
jobs: | ||
eslint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ inputs.nodeVersion }} | ||
cache: 'npm' | ||
- name: Install Node Dependencies | ||
run: npm ci | ||
env: | ||
CI: TRUE | ||
- name: Save Code Linting Report JSON | ||
run: npm run lint:ci | ||
continue-on-error: true | ||
- name: Annotate Code Linting Results | ||
uses: ataylorme/eslint-annotate-action@v2 | ||
with: | ||
only-pr-files: false | ||
fail-on-warning: true | ||
fail-on-error: true | ||
markdown-report-on-step-summary: true | ||
- name: Upload ESLint report | ||
if: always() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: eslint_report.json | ||
path: eslint_report.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# | ||
# This source file is part of the Stanford Biodesign Digital Health Group open-source organization | ||
# Based on the GitHub default template workflow for building and deploying a Next.js site to GitHub Pages | ||
# | ||
# SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
|
||
name: Deploy Next.js site to GitHub Pages | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
nodeVersion: | ||
description: 'Node version spec of the version to use in SemVer notation.' | ||
required: false | ||
type: string | ||
default: '18' | ||
|
||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
concurrency: | ||
group: 'pages' | ||
cancel-in-progress: false | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ inputs.nodeVersion }} | ||
cache: 'npm' | ||
- name: Install Node Dependencies | ||
run: npm ci | ||
env: | ||
CI: TRUE | ||
- name: Build & Export with Next.js | ||
run: npm run build | ||
env: | ||
NEXT_JS_OUTPUT: 'export' | ||
NEXT_JS_BASE_PATH: '/${{ github.event.repository.name }}' | ||
NEXT_JS_IMAGES_UNOPTIMIZED: true | ||
- name: Build Docs | ||
run: npm run docs:ci --if-present | ||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v2 | ||
with: | ||
path: ./out | ||
deploy: | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
runs-on: ubuntu-latest | ||
needs: build | ||
steps: | ||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# | ||
# This source file is part of the Stanford Biodesign Digital Health Group open-source organization | ||
# | ||
# SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
|
||
name: Test and Coverage | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
nodeVersion: | ||
description: 'Node version spec of the version to use in SemVer notation.' | ||
required: false | ||
type: string | ||
default: '18' | ||
|
||
jobs: | ||
testandcoverage: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ inputs.nodeVersion }} | ||
cache: 'npm' | ||
- name: Install Node Dependencies | ||
run: npm ci | ||
env: | ||
CI: TRUE | ||
- name: Run the tests | ||
run: npm test | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v3 |