Add gha cache to docker build #527
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 | |
on: push | |
jobs: | |
test: | |
runs-on: ubuntu-22.04 | |
services: | |
db: | |
image: postgres:10 | |
env: | |
POSTGRES_DB: accent_test | |
POSTGRES_PASSWORD: password | |
ports: ['5432:5432'] | |
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | |
env: | |
MIX_ENV: test | |
DATABASE_URL: postgres://postgres:password@localhost/accent_test | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- uses: erlef/setup-beam@v1 | |
id: setup-beam | |
with: | |
version-file: .tool-versions | |
version-type: strict | |
- uses: actions/cache@v3 | |
with: | |
path: | | |
deps | |
_build | |
priv/plts | |
key: ${{ runner.os }}-mix-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ hashFiles(format('{0}/mix.lock', github.workspace)) }} | |
- uses: actions/setup-node@v3 | |
with: | |
node-version-file: .tool-versions | |
cache: npm | |
cache-dependency-path: | | |
package-lock.json | |
cli/package-lock.json | |
jipt/package-lock.json | |
webapp/package-lock.json | |
- name: Install System Dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y gcc libyaml-dev | |
- name: Install Elixir Dependencies | |
run: | | |
mix local.rebar --force | |
mix local.hex --force | |
mix deps.get | |
mix deps.compile | |
- name: Install NodeJS Dependencies | |
run: | | |
npm config set spin false | |
npm ci --no-audit --no-color | |
npm ci --prefix webapp --no-audit --no-color | |
npm ci --prefix cli --no-audit --no-color | |
npm ci --prefix jipt --no-audit --no-color | |
- name: Build webapp production | |
run: npm run build-production-inline --prefix webapp | |
- name: Run Tests | |
run: | | |
mix ecto.setup | |
./priv/scripts/ci-check.sh | |
- name: Build CLI | |
run: npm --prefix cli run build | |
- name: Build JIPT | |
run: npm --prefix jipt run build-production-inline | |
- name: Coverage report | |
run: mix coveralls.post --token ${{ secrets.COVERALLS_REPO_TOKEN }} --name 'github-actions' --branch ${{ github.ref }} --committer ${{ github.actor }} --sha ${{ github.sha }} | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.MIREGO_GITHUB_PACKAGES_ACCESS_TOKEN }} | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
mirego/accent | |
ghcr.io/mirego/accent | |
tags: | | |
type=raw,value=latest,enable={{is_default_branch}} | |
type=semver,pattern={{raw}} | |
- uses: docker/build-push-action@v5 | |
with: | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
context: . | |
push: ${{ startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |