I have read this SO for deploying My small PHP`s Project. So far, I am successfully in CI process, that marks by I already push My app docker image with latest tag on it.
But, for newbie like me, what's step for sending my Docker image into a Droplet's DO (continous delivery)?
Which is in those Droplet`s DO, I just use docker-compose for running the docker image: Here is my github action .yml:
name: CI
on:
push:
branches: ["main"]
jobs:
run-composer-and-docker-build:
name: Continuous integration
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Setup PHP with composer v2
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
tools: composer:v2
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Running composer install
run: composer install --no-dev
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
target: deploy
file: "./.docker/php/debian-apache/Dockerfile"
push: true
tags: username/app:latest
cache-from: type=registry,ref=username/app:latest
cache-to: type=inline
And here is my docker-compose.yml,
version: "3.7"
services:
db:
image: mysql:8.0.28-oracle
hostname: mysql
container_name: ${APP_NAME}-db
tty: false
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_DATABASE: ${DB_NAME}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
volumes:
- ${APP_NAME}-volumes:/var/lib/mysql/
- ./.docker/mysql/my.cnf:/etc/mysql/my.cnf
networks:
- ${APP_NAME}-network
ports:
- ${DB_PORT}:3306
php:
platform: linux/amd64
image: "${REGISTRY_HOST}/${APP_NAME}-php:latest"
hostname: php
container_name: ${APP_NAME}-php
tty: true
working_dir: /var/www/html
ports:
- "${WEB_SERVER_PORT}:80"
env_file:
- .env
networks:
- ${APP_NAME}-network
depends_on:
- db
mongodb:
image: mongo:5.0.6
container_name: ${APP_NAME}-mongo
environment:
MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE}
MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
volumes:
- ${APP_NAME}-mongo-volumes:/data/db
- ./.docker/mongo/:/docker-entrypoint-initdb.d/:ro
ports:
- ${MONGO_PORT}:27017
networks:
- ${APP_NAME}-network
# Docker Networks
networks:
stm-network:
driver: bridge
# Docker Volumes
volumes:
stm-volumes:
driver: local
stm-mongo-volumes:
driver: local
For running the app in DO's droplet, I have to pull manually the My app docker image by
docker-compose down
docker-compose pull
docker-compose up -d
Any advise and suggestion is so appreciated.