Skip to content

fix docker compose

fix docker compose #21

Workflow file for this run

name: CI
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
workflow_dispatch:
env:
REGISTRY: ghcr.io
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: cascade_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
env:
MIX_ENV: test
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/cascade_test
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: '1.19.4'
otp-version: '28.1'
- name: Restore dependencies cache
uses: actions/cache@v3
with:
path: |
deps
_build
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Install dependencies
run: mix deps.get
- name: Compile dependencies
run: mix deps.compile
- name: Compile application
run: mix compile --warnings-as-errors
- name: Run database migrations
run: mix ecto.create && mix ecto.migrate
- name: Run tests (including property tests)
run: mix test --include test
docker-build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/cascade
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build Docker image (no push)
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=docker,dest=/tmp/cascade-image.tar
- name: Upload Docker image artifact
uses: actions/upload-artifact@v4
with:
name: cascade-docker-image
path: /tmp/cascade-image.tar
retention-days: 1
docker-push:
runs-on: ubuntu-latest
needs: [test, docker-build]
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download Docker image artifact
uses: actions/download-artifact@v4
with:
name: cascade-docker-image
path: /tmp
- name: Load Docker image
run: docker load --input /tmp/cascade-image.tar
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/cascade
tags: |
type=ref,event=branch
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Push Docker image to registry
run: |
for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr ',' ' '); do
docker tag $(docker images -q | head -n1) $tag
docker push $tag
done