Containerize #13
Workflow file for this run
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: Node.js Image tests | |
on: | |
push: | |
branches: [master] | |
pull_request: | |
branches: [master] | |
jobs: | |
build-and-test: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
architecture: [linux/amd64, linux/arm64] | |
# Define service containers for Redis | |
services: | |
redis: | |
image: redis:6 | |
ports: | |
- 6379:6379 | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v3 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Cache Docker layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }}-${{ matrix.architecture }} | |
restore-keys: | | |
${{ runner.os }}-buildx-${{ matrix.architecture }}- | |
- name: Build Docker image | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
file: ./Dockerfile | |
target: builder | |
tags: my-node-app-builder:latest | |
load: true | |
platforms: ${{ matrix.architecture }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new | |
- name: Get Redis network name | |
id: redis_network | |
run: echo "::set-output name=network_name::$(docker network ls --filter name=_default -q)" | |
- name: Run tests in Docker container | |
run: | | |
docker run --rm \ | |
--network name=${{ job.services.redis.network }} \ | |
-e BLOT_REDIS_HOST=redis \ | |
my-node-app-builder sh -c "node app/setup && npm test" | |
- name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache |