Skip to content

Build/001

Build/001 #19

Workflow file for this run

name: Docker 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: ${{ runner.temp }}/.buildx-cache # Use GitHub Actions cache directory
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build image
uses: docker/build-push-action@v5
with:
cache-from: type=local,src=${{ runner.temp }}/.buildx-cache
cache-to: type=local,mode=max,dest=${{ runner.temp }}/.buildx-cache-new
context: .
target: build
tags: ${{ env.TEST_IMAGE_TAG }}
outputs: type=docker,dest=${{ runner.temp }}/${{ env.TEMP_IMAGE_NAME }}.tar
- name: Move cache
run: |
rm -rf ${{ runner.temp }}/.buildx-cache
mv ${{ runner.temp }}/.buildx-cache-new ${{ runner.temp }}/.buildx-cache
- name: Load built image
run: docker load -i ${{ runner.temp }}/${{ env.TEMP_IMAGE_NAME }}.tar
- name: Run Tests
run: |
docker compose up -d database
docker compose run --rm -e RAILS_ENV=test web bin/rails db:test:prepare
docker compose run --rm -e RAILS_ENV=test web bin/rails spec
- name: Login to DockerHub (if main branch)
if: github.ref == 'refs/heads/main'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push Docker Image (if main branch)
if: github.ref == 'refs/heads/main'
uses: docker/build-push-action@v5
with:
cache-from: type=local,src=${{ runner.temp }}/.buildx-cache
context: .
push: true
target: deployment
tags: xavius/wave-connect:${{ github.sha }}, xavius/wave-connect:latest
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 ...