Skip to content

Instantly share code, notes, and snippets.

@isabelatravaglia
Last active May 25, 2021 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isabelatravaglia/3714ed4d4f9ecab3d2e4fbf47c252e63 to your computer and use it in GitHub Desktop.
Save isabelatravaglia/3714ed4d4f9ecab3d2e4fbf47c252e63 to your computer and use it in GitHub Desktop.
GHA test workflow - Building all the containers using Dockerfiles
name: Test with Dockerfiles
on: [push]
jobs:
test:
env:
RAILS_ENV: test
NODE_ENV: test
runs-on: ubuntu-latest # runner
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
version: latest
install: true
- name: Prepare Tags
id: tags
run: |
TAG=$(echo $GITHUB_SHA | head -c7)
IMAGE="dev/test"
echo ::set-output name=tagged_image::${IMAGE}:${TAG}
echo ::set-output name=tag::${TAG}
- name: Cache main image layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-main-cache
key: ${{ runner.os }}-buildx-main-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-main-
- name: Cache postgres image layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-postgres-cache
key: ${{ runner.os }}-buildx-postgres-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-postgres-
- name: Cache chrome image layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-chrome-cache
key: ${{ runner.os }}-buildx-chrome-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-chrome-
- name: Build code
uses: docker/build-push-action@v2
with:
push: false
file: .ci/Dockerfile.ci
load: true
cache-from: type=local,src=/tmp/.buildx-main-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-main-cache-new
tags: ${{ steps.tags.outputs.tagged_image }}
- name: Build DB
uses: docker/build-push-action@v2
with:
push: false
file: .ci/Dockerfile.postgres
load: true
cache-from: type=local,src=/tmp/.buildx-postgres-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-postgres-cache-new
tags: db-${{ steps.tags.outputs.tagged_image }}
- name: Build Chrome
uses: docker/build-push-action@v2
with:
push: false
file: .ci/Dockerfile.chrome
load: true
cache-from: type=local,src=/tmp/.buildx-chrome-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-chrome-cache-new
tags: chrome-${{ steps.tags.outputs.tagged_image }}
- name: Run Tests
run: |
TEST_IMAGE_TAG=${{ steps.tags.outputs.tagged_image }} DB_IMAGE_TAG=db-${{ steps.tags.outputs.tagged_image }} CHROME_IMAGE_TAG=chrome-${{ steps.tags.outputs.tagged_image }} docker-compose -f .ci/docker-compose.test.yml run test
# Temp fix for growing cache
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-main-cache
mv /tmp/.buildx-main-cache-new /tmp/.buildx-main-cache
rm -rf /tmp/.buildx-postgres-cache
mv /tmp/.buildx-postgres-cache-new /tmp/.buildx-postgres-cache
rm -rf /tmp/.buildx-chrome-cache
mv /tmp/.buildx-chrome-cache-new /tmp/.buildx-chrome-cache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment