Build/001 #15
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: 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: Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
- 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: Login to DockerHub | |
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: | |
context: . | |
push: true | |
target: deployment | |
tags: xavius/wave-connect:${{ github.sha }}, xavius/wave-connect:latest | |
#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 ... |