From 8f7320e666889121e4d61984098147ce1e1edd55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Wed, 26 May 2021 15:38:25 +0200 Subject: [PATCH] Automate building Docker images --- .github/workflows/assets.yaml | 47 ----------------- .github/workflows/deploy.yaml | 95 +++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 47 deletions(-) delete mode 100644 .github/workflows/assets.yaml create mode 100644 .github/workflows/deploy.yaml diff --git a/.github/workflows/assets.yaml b/.github/workflows/assets.yaml deleted file mode 100644 index 90c01383b..000000000 --- a/.github/workflows/assets.yaml +++ /dev/null @@ -1,47 +0,0 @@ -name: Assets build -on: - push: - branches: - - main -jobs: - main: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Install Erlang & Elixir - uses: erlef/setup-beam@v1 - with: - otp-version: '24.0' - elixir-version: '1.12.0' - - name: Cache Mix - uses: actions/cache@v2 - with: - path: | - deps - _build - key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} - restore-keys: | - ${{ runner.os }}-mix- - # Note: we need to get Phoenix and LV because package.json points to them directly - - name: Install mix dependencies - run: mix deps.get - - name: Install Node - uses: actions/setup-node@v2 - with: - node-version: '14.x' - - name: Cache npm dependencies - uses: actions/cache@v2 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - name: Install npm dependencies - run: npm ci --prefix assets - - name: Build assets - run: npm run deploy --prefix assets - - name: Update assets - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: Update assets - file_pattern: priv/static diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 000000000..1a7f6fe5d --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,95 @@ +name: Deploy +on: + push: + branches: + - main + tags: + - 'v*.*.*' +jobs: + assets: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install Erlang & Elixir + uses: erlef/setup-beam@v1 + with: + otp-version: '24.0' + elixir-version: '1.12.0' + - name: Cache Mix + uses: actions/cache@v2 + with: + path: | + deps + _build + key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} + restore-keys: | + ${{ runner.os }}-mix- + # Note: we need to get Phoenix and LV because package.json points to them directly + - name: Install mix dependencies + run: mix deps.get + - name: Install Node + uses: actions/setup-node@v2 + with: + node-version: '14.x' + - name: Cache npm dependencies + uses: actions/cache@v2 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - name: Install npm dependencies + run: npm ci --prefix assets + - name: Build assets + run: npm run deploy --prefix assets + - name: Update assets + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Update assets + file_pattern: priv/static + docker: + # The assets job may push new commit, so we wait for it + needs: assets + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v3 + with: + images: livebook/livebook + tags: | + type=semver,pattern={{version}} + type=edge,branch=main + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + # TODO: switch to type=gha once available: + # * pending PR: https://github.com/moby/buildkit/pull/1974 + # * context: https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#github-cache + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache