From c2f48c68961c21f77b5b7620f66f6430f2775861 Mon Sep 17 00:00:00 2001 From: Bruce Lacey Date: Fri, 5 Feb 2021 16:20:03 -0500 Subject: [PATCH] Continuous Integration and Docker publishing workflows --- .github/dependabot.yml | 15 ++++++ .github/workflows/ci.yml | 34 +++++++++++++ .github/workflows/docker-publish.yml | 72 ++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..d21c654 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,15 @@ +version: 2 + +updates: + # NPM + - package-ecosystem: "npm" # See documentation for possible values + directory: "/node-app" # Location of package manifests + schedule: + interval: "daily" + + # GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..427963b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,34 @@ +name: Continuous Integration + +on: + push: + branches: + - '**' + pull_request: + workflow_dispatch: + +jobs: + build: + name: Build (Node ${{matrix.node}}) + + strategy: + matrix: + node: ['12', '15'] + runs-on: ubuntu-20.04 + + steps: + - name: Github setup & checkout + uses: actions/checkout@v2 + with: + persist-credentials: false + + - name: Setup Node.js ${{matrix.node}} + uses: actions/setup-node@v2 + with: + node-version: ${{matrix.node}} + + - name: CI Build & Install + run: | + cd node-app + npm install + npm run build --if-present diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..079aef0 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,72 @@ +name: Docker to ghcr.io + +on: + release: + types: [created] + + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + + - name: Run tests + run: docker-compose --file docker-compose.yml build + + push: + needs: test + + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Builder + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Available platforms + run: echo ${{ steps.buildx.outputs.platforms }} + + - name: Log into GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GCR_PAT }} + + - name: Setup Environment + run: | + echo "IMAGE=ghcr.io/${{ github.repository }}" >> $GITHUB_ENV + echo "VERSION=${GITHUB_REF#refs/*/v}" >> $GITHUB_ENV + echo "GITHUB_SHORT_SHA=${GITHUB_SHA:1:7}" >> $GITHUB_ENV + echo "GITHUB_REFNAME=${GITHUB_REF#refs/*/}" >> GITHUB_ENV + echo "BUILD_DATE=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV + + - name: Build image and push + uses: docker/build-push-action@v2 + with: + context: node-app + platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 + labels: | + org.opencontainers.image.title=EZ-HouseMode-SceneRunner + org.opencontainers.image.authors=bruce@blacey.com + org.opencontainers.image.source=https://github.com/${{ github.repository }} + org.opencontainers.image.description=Created from commit ${{ env.GITHUB_SHORT_SHA }}, (ref ${{ env.GITHUB_REF_NAME }}) + org.opencontainers.image.created=${{ env.BUILD_DATE }} + org.opencontainers.image.revision=${{ github.sha }} + org.opencontainers.image.ref.name=${{ env.GITHUB_REFNAME }} + org.opencontainers.image.version=${{ env.VERSION }} + tags: | + ${{ env.IMAGE }}:latest + ${{ env.IMAGE }}:${{ env.VERSION }} + push: true + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }}