diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 000d73e..7f1f5d4 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,7 +5,15 @@ version: 2 updates: - - package-ecosystem: "npm" # See documentation for possible values - directory: "/" # Location of package manifests + + # Check for Github Actions version updates (for CI/CD) + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + + # Check for npm package updates + - package-ecosystem: "npm" + directory: "/" schedule: interval: "daily" diff --git a/.github/workflows/ci-develop.yml b/.github/workflows/ci-develop.yml new file mode 100644 index 0000000..6cda78b --- /dev/null +++ b/.github/workflows/ci-develop.yml @@ -0,0 +1,104 @@ +on: + push: + branches: + - develop + pull_request: + branches: + - develop + types: [opened, reopened, synchronize] + +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: + REGISTRY: ghcr.io + ARTIFACT_NAME: shocklink-webui.zip + IMAGE_NAME: ${{ github.repository_owner }}/shocklink-webui + TARGET_ENV: development + NODE_ENV: development + +jobs: + + build-ui: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v3 + with: + node-version: 17.x + + - uses: actions/cache@v3 + with: + path: | + ~/.npm + key: npm-${{ hashFiles('package-lock.json') }} + restore-keys: npm- + + - name: Install dependencies + run: npm install + + - name: Build + run: npm run build --if-present + + - name: Compress internal artifacts + run: | + cd dist + zip -r ${{ env.ARTIFACT_NAME }} . + cd .. + mv dist/${{ env.ARTIFACT_NAME }} . + + - 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: + runs-on: ubuntu-latest + needs: build-ui + + steps: + - uses: actions/checkout@v4 + with: + sparse-checkout: | + Dockerfile + + - name: Download internal artifacts + uses: actions/download-artifact@v3 + with: + name: ${{ env.ARTIFACT_NAME }} + + - name: Extract artifacts + run: unzip ${{ env.ARTIFACT_NAME }} -d dist + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - 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=ref,event=branch + type=ref,event=pr + + - name: Build image + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/ci-master.yml b/.github/workflows/ci-master.yml new file mode 100644 index 0000000..ef858bd --- /dev/null +++ b/.github/workflows/ci-master.yml @@ -0,0 +1,107 @@ +on: + push: + branches: + - master + pull_request: + branches: + - master + types: [opened, reopened, synchronize] + +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: + REGISTRY: ghcr.io + ARTIFACT_NAME: shocklink-webui.zip + IMAGE_NAME: ${{ github.repository_owner }}/shocklink-webui + TARGET_ENV: production + NODE_ENV: production + +jobs: + + build-ui: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v3 + with: + node-version: 17.x + + - uses: actions/cache@v3 + with: + path: | + ~/.npm + ~/node_modules + key: npm-${{ hashFiles('package-lock.json') }} + restore-keys: npm- + + - name: Install dependencies + 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: | + cd dist + zip -r ${{ env.ARTIFACT_NAME }} . + cd .. + mv dist/${{ env.ARTIFACT_NAME }} . + + - 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: + runs-on: ubuntu-latest + needs: build-ui + + steps: + - uses: actions/checkout@v4 + with: + sparse-checkout: | + Dockerfile + + - name: Download internal artifacts + uses: actions/download-artifact@v3 + with: + name: ${{ env.ARTIFACT_NAME }} + + - name: Extract artifacts + run: unzip ${{ env.ARTIFACT_NAME }} -d dist + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - 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=ref,event=branch + type=ref,event=pr + + - name: Build image + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/ci-tag.yml b/.github/workflows/ci-tag.yml new file mode 100644 index 0000000..196fc2c --- /dev/null +++ b/.github/workflows/ci-tag.yml @@ -0,0 +1,122 @@ +on: + push: + tags: + - 'v*' + +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 + NODE_ENV: production + +jobs: + + build-ui: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v3 + with: + node-version: 17.x + + - uses: actions/cache@v3 + with: + path: | + ~/.npm + key: npm-${{ hashFiles('package-lock.json') }} + restore-keys: npm- + + - name: Install dependencies + 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: | + cd dist + zip -r ${{ env.ARTIFACT_NAME }} . + cd .. + mv dist/${{ env.ARTIFACT_NAME }} . + + - name: Upload internal artifacts + uses: actions/upload-artifact@v3 + with: + name: ${{ env.ARTIFACT_NAME }} + path: ${{ github.workspace }}/${{ env.ARTIFACT_NAME }} + retention-days: 1 + + publish-artifacts: + 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 + + steps: + - uses: actions/checkout@v4 + with: + sparse-checkout: | + Dockerfile + + - name: Download internal artifacts + uses: actions/download-artifact@v3 + with: + name: ${{ env.ARTIFACT_NAME }} + + - name: Extract artifacts + run: unzip ${{ env.ARTIFACT_NAME }} -d dist + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - 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=latest + type=ref,event=tag + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }} + + - name: Build image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..410596b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,2 @@ +FROM nginx:1-alpine +COPY dist /usr/share/nginx/html