CI/CD #339
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
name: CI/CD | |
on: | |
push: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 0 * * 0' | |
jobs: | |
build: | |
strategy: | |
matrix: | |
version: [16, 18] | |
runs-on: [ubuntu-latest, buildjet-4vcpu-ubuntu-2204-arm] | |
runs-on: ${{ matrix.runs-on }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Cache Docker layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: docker-buildx-${{ matrix.version }}-${{ github.sha }} | |
restore-keys: docker-buildx-${{ matrix.version }}- | |
- name: Build | |
run: | | |
docker buildx build \ | |
--cache-from type=local,src=/tmp/.buildx-cache/${{ matrix.version }} \ | |
--cache-to type=local,dest=/tmp/.buildx-cache/${{ matrix.version }} \ | |
--output type=docker \ | |
--tag kooldev/node:${{ matrix.version }}-$(arch) \ | |
${{ matrix.version }} | |
- name: Tests | |
run: | | |
docker run kooldev/node:${{ matrix.version }}-$(arch) node -v; | |
docker run kooldev/node:${{ matrix.version }}-$(arch) npm -v; | |
docker run kooldev/node:${{ matrix.version }}-$(arch) yarn -v; | |
docker run -e ASUSER=1000 kooldev/node:${{ matrix.version }}-$(arch) node -v; | |
docker run -e ASUSER=1000 kooldev/node:${{ matrix.version }}-$(arch) npm -v; | |
docker run -e ASUSER=1000 kooldev/node:${{ matrix.version }}-$(arch) yarn -v; | |
- name: Login to DockerHub | |
uses: docker/login-action@v2 | |
if: github.ref == 'refs/heads/master' && github.repository == 'kool-dev/docker-node' | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Push to DockerHub | |
if: github.ref == 'refs/heads/master' && github.repository == 'kool-dev/docker-node' | |
run: | | |
docker push kooldev/node:${{ matrix.version }}-$(arch) | |
amend: | |
if: github.ref == 'refs/heads/master' && github.repository == 'kool-dev/docker-node' | |
needs: build | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
version: [16, 18] | |
steps: | |
- uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- run: | | |
docker manifest create kooldev/node:${{ matrix.version }} \ | |
--amend kooldev/node:${{ matrix.version }}-x86_64 \ | |
--amend kooldev/node:${{ matrix.version }}-aarch64 | |
docker manifest push kooldev/node:${{ matrix.version }} |