- APP_NAME (GLOBAL, set to your-app-name)
- APP_ENV (set in gitlab.ci.yml)
- APP_KEY
- APP_DEBUG
- DB_CONNECTION
- DB_HOST
- DB_PORT
- DB_DATABASE
- DB_USERNAME
- DB_PASSWORD
Config:
- Copy .env.example and rename it to .env
- Modify .env with your own environment
- If project location is outside of the root folder (for local development only):
by defaultDOCKER_USER=0
export DOCKER_USER=$(id -u):$(id -g)
- To change docker host:
by defaultDOCKER_HOST=80
orexport DOCKER_HOST=xxxx
export DOCKER_HOST=xxx.xxx.xx.xx:xxxx
Run Command:
docker-compose up -d
If you change Dockerfile, and want to apply it:
docker-compose up -d --build
If running using docker and got error from laravel failed to open stream - Permission denied => Solved using LOG_CHANNEL=stderr, do not run chmod to the project folder (your git will get so messy)
Stop Command:
docker-compose down
EC2 Setup for Docker:
- Launch EC2 Instance.
- SSH to new created server.
- Install docker, git
- Make sure your docker will start automatically if system reboot
- Configure git in ssh server (https://docs.gitlab.com/ee/ssh/#generating-a-new-ssh-key-pair)
ssh-keygen -o -t rsa -b 4096
- Read rsa pub key, using cat command.
cat .ssh/id_rsa.pub
- Git clone the project (choose your name wisely because this will be used in gitlab-ci.yml file for automation purpose -> SSH_DEV_PROJECT_PATH)
Gitlab CI/CD Jobs (deploy-development):
- Go to Gitlab Project > Settings > CI / CD > Variables
- Set ENV with prefix ENV_DEV_ exclude GLOBAL
- Set:
- SSH_DEV_PRIVATE_KEY
- SSH_DEV_URL
- SSH_DEV_USER
- SSH_DEV_PROJECT_PATH
- Every push to branch master will create a new pipeline (trigger the deploy-development job manually)
Gitlab CI/CD Jobs (build and deploy-production):
- Create ecsTaskExecutionRole role if does not exists (follow this guide)
- Go to Gitlab Project > Settings > CI / CD > Variables
- Set ENV with prefix ENV_PROD_ exclude GLOBAL
- Set:
- ECS_PROD_ACCESS_KEY_ID
- ECS_PROD_SECRET_ACCESS_KEY
- ECS_PROD_REGION
- ECR_PROD_SITE_APP
- ECR_PROD_WEB_SERVER
- ECS_PROD_SUBNET_1 (if you want to add more subnet, you need to modify the gitlab.ci.yml config)
- ECS_PROD_TARGET_GROUP_ARN
- Every push to branch master will create a new pipeline (build will be executed automatically, to deploy production you need to trigger the deploy-production job manually)
SENPAI TEACH DEVOPS PLS!