Merge pull request #25 from NickMous/feature/add-docker #25
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: Deploy Laravel App to production | |
env: | |
PUBLIC_PATH: "/var/www/html/nl/CycleQuest" | |
BUILD_PATH: "/var/www/html/nl/" | |
BUILD_REPO: "CycleQuest" | |
on: | |
push: | |
branches: [main] | |
jobs: | |
laravel-tests: | |
runs-on: ubuntu-latest | |
services: | |
docker: | |
image: docker | |
options: --privileged | |
ports: | |
- 3306:3306 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ vars.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Copy password file | |
run: cp database/password.txt.example database/password.txt | |
- name: Copy .env file | |
run: cp .env.example .env | |
- name: Set app key | |
run: sed -i "s|APP_KEY=|APP_KEY=base64:$(openssl rand -base64 32)|" .env | |
- name: Set up Docker Compose | |
run: | | |
docker compose -f compose.testing.yaml up -d | |
- name: Run tests | |
run: | | |
docker compose -f compose.testing.yaml --env-file .env exec server-testing ./vendor/bin/pest tests | |
- name: Tear down Docker Compose | |
run: | | |
docker compose -f compose.testing.yaml down | |
deploy: | |
needs: laravel-tests | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ vars.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v6 | |
with: | |
platform: linux/amd64,linux/arm64 | |
push: true | |
target: prod | |
tags: ${{ secrets.DOCKER_USERNAME }}/cyclequest:latest |