Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:Shock-Link/WebUI into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
redmushie committed Oct 1, 2023
2 parents 8862620 + 2440be2 commit a942bce
Show file tree
Hide file tree
Showing 39 changed files with 1,159 additions and 470 deletions.
32 changes: 17 additions & 15 deletions .github/workflows/ci-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ name: ci-develop
# REGISTRY and IMAGE_NAME are for building and tagging the container.
# TARGET_ENV is used by Webpack to determine the build target.
env:
BRANCH: develop
REGISTRY: ghcr.io
ARTIFACT_NAME: shocklink-webui.zip
IMAGE_NAME: ${{ github.repository_owner }}/shocklink-webui
TARGET_ENV: development
IMAGE_NAME: ${{ github.repository_owner }}/webui
TARGET_ENV: container
NODE_ENV: development

jobs:

build-ui:
build:
runs-on: ubuntu-latest

steps:
Expand All @@ -38,32 +39,36 @@ jobs:
restore-keys: npm-

- name: Install dependencies
run: npm install --development
run: npm install

- name: Build
run: npm run build --if-present

- name: Compress the artifact
run: zip -r ${{ env.ARTIFACT_NAME }} dist
- name: Compress internal artifacts
run: |
cd dist
zip -r ${{ env.ARTIFACT_NAME }} .
cd ..
mv dist/${{ env.ARTIFACT_NAME }} .
- name: Upload artifact
- name: Upload internal artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ github.workspace }}/${{ env.ARTIFACT_NAME }}
retention-days: 1

build-container:
containerize:
runs-on: ubuntu-latest
needs: build-ui
needs: build

steps:
- uses: actions/checkout@v4
with:
sparse-checkout: |
Dockerfile
- name: Download artifacts
- name: Download internal artifacts
uses: actions/download-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}
Expand All @@ -81,23 +86,20 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# - Tag as 'master' when master branch is pushed
# - Tag as pr-{n} when a PR is created
# -
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value={{branch}},enable=${{ github.ref_name == 'develop' }}
type=raw,value={{branch}},enable=${{ github.ref_name == env.BRANCH }}
type=ref,event=branch
type=ref,event=pr
- name: Build image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_Name != 'pull_request' }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
35 changes: 20 additions & 15 deletions .github/workflows/ci-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ name: ci-master
# REGISTRY and IMAGE_NAME are for building and tagging the container.
# TARGET_ENV is used by Webpack to determine the build target.
env:
BRANCH: master
REGISTRY: ghcr.io
ARTIFACT_NAME: shocklink-webui.zip
IMAGE_NAME: ${{ github.repository_owner }}/shocklink-webui
TARGET_ENV: production
IMAGE_NAME: ${{ github.repository_owner }}/webui
TARGET_ENV: container
NODE_ENV: production

jobs:

build-ui:
build:
runs-on: ubuntu-latest

steps:
Expand All @@ -34,36 +35,43 @@ jobs:
with:
path: |
~/.npm
~/node_modules
key: npm-${{ hashFiles('package-lock.json') }}
restore-keys: npm-

- name: Install dependencies
run: npm install --development
run: npm install --production=false
# ^
# This is necessary since NODE_ENV=production, but we need dev dependencies to build.

- name: Build
run: npm run build --if-present

- name: Compress the artifact
run: zip -r ${{ env.ARTIFACT_NAME }} dist
- name: Compress internal artifacts
run: |
cd dist
zip -r ${{ env.ARTIFACT_NAME }} .
cd ..
mv dist/${{ env.ARTIFACT_NAME }} .
- name: Upload artifact
- name: Upload internal artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ github.workspace }}/${{ env.ARTIFACT_NAME }}
retention-days: 1

build-container:
containerize:
runs-on: ubuntu-latest
needs: build-ui
needs: build

steps:
- uses: actions/checkout@v4
with:
sparse-checkout: |
Dockerfile
- name: Download artifacts
- name: Download internal artifacts
uses: actions/download-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}
Expand All @@ -81,23 +89,20 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# - Tag as 'master' when master branch is pushed
# - Tag as pr-{n} when a PR is created
# -
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value={{branch}},enabled={{is_default_branch}}
type=raw,value={{branch}},enable=${{ github.ref_name == env.BRANCH }}
type=ref,event=branch
type=ref,event=pr
- name: Build image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_Name != 'pull_request' }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
68 changes: 41 additions & 27 deletions .github/workflows/push-tag.yml → .github/workflows/ci-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ on:
tags:
- 'v*'

name: push-tag
name: ci-tag

# REGISTRY and IMAGE_NAME are for building and tagging the container.
# TARGET_ENV is used by Webpack to determine the build target.
env:
REGISTRY: ghcr.io
ARTIFACT_NAME: shocklink-webui.zip
IMAGE_NAME: ${{ github.repository_owner }}/shocklink-webui
TARGET_ENV: production
IMAGE_NAME: ${{ github.repository_owner }}/webui
TARGET_ENV: container
NODE_ENV: production

jobs:

build-ui:
build:
runs-on: ubuntu-latest

steps:
Expand All @@ -34,13 +34,19 @@ jobs:
restore-keys: npm-

- name: Install dependencies
run: npm install --development
run: npm install --production=false
# ^
# This is necessary since NODE_ENV=production, but we need dev dependencies to build.

- name: Build
run: npm run build --if-present

- name: Compress internal artifacts
run: zip -r ${{ env.ARTIFACT_NAME }} dist
run: |
cd dist
zip -r ${{ env.ARTIFACT_NAME }} .
cd ..
mv dist/${{ env.ARTIFACT_NAME }} .
- name: Upload internal artifacts
uses: actions/upload-artifact@v3
Expand All @@ -49,27 +55,9 @@ jobs:
path: ${{ github.workspace }}/${{ env.ARTIFACT_NAME }}
retention-days: 1

publish-artifacts:
containerize:
runs-on: ubuntu-latest
needs: build-ui

steps:
- name: Download internal artifacts
uses: actions/download-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}

- name: Upload artifacts to tag
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ env.ARTIFACT_NAME }}
asset_name: ${{ env.ARTIFACT_NAME }}
tag: ${{ github.ref }}

build-container:
runs-on: ubuntu-latest
needs: build-ui
needs: build

steps:
- uses: actions/checkout@v4
Expand All @@ -95,13 +83,21 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- uses: oprypin/find-latest-tag@v1
id: latest-tag
with:
repository: ${{ github.repository }}
releases-only: false

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=false
tags: |
type=raw,value=latest
type=raw,value=latest,enable=${{ steps.latest-tag.outputs.tag == github.ref_name }}
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
Expand All @@ -114,3 +110,21 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

publish:
runs-on: ubuntu-latest
needs: containerize

steps:
- name: Download internal artifacts
uses: actions/download-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}

- name: Upload artifacts to tag
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ env.ARTIFACT_NAME }}
asset_name: ${{ env.ARTIFACT_NAME }}
tag: ${{ github.ref }}
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
FROM nginx:1-alpine

ENV SHOCKLINK_API_URL=https://api.shocklink.net
ENV SHOCKLINK_WEBUI_URL=https://shocklink.net/#/
ENV SHOCKLINK_SHARE_URL=https://shockl.ink/

# Copy release artifacts (static JS and CSS bundles)
COPY dist /usr/share/nginx/html

# Copy custom startup script.
# This script performs environment variable substitution!
COPY startup.sh .
RUN ["chmod", "+x", "/startup.sh"]

# Start up nginx using the alternative entrypoint, but with the default CMD.
# See: https://github.com/nginxinc/docker-nginx/blob/master/mainline/debian/Dockerfile#L113-L119
ENTRYPOINT ["/startup.sh"]
CMD ["nginx", "-g", "daemon off;"]
Loading

0 comments on commit a942bce

Please sign in to comment.