Skip to content

Workflow file for this run

name: Docker Image CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
RAILS_ENV: test
TEST_IMAGE_TAG: wave:test
TEMP_IMAGE_NAME: image_
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-multi-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-multi-buildx
- name: Build image
uses: docker/build-push-action@v5
with:
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
context: .
target: build
tags: ${{ env.TEST_IMAGE_TAG }}
outputs: type=docker,dest=/tmp/${{ env.TEMP_IMAGE_NAME }}.tar
- name: Load built image
run: docker load -i /tmp/${{ env.TEMP_IMAGE_NAME }}.tar
- name: DB Test Prepare
run: |
docker compose up -d database
docker compose run --rm -e RAILS_ENV=test web bin/rails db:test:prepare
- name: Run Tests
run: docker compose run --rm -e RAILS_ENV=test web bin/rails spec
- name: Push Docker Image (if on main)
if: github.ref == 'refs/heads/main'
uses: docker/build-push-action@v5
with:
context: .
push: true
target: deployment
tags: ${{ env.TEST_IMAGE_TAG }}
#repository: your-docker-hub-username/your-repository-name
deploy:
needs: build-and-test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
environment: production
steps:
- name: Deploy to Production
run: |
# ... your deployment commands ...