Skip to content

Instantly share code, notes, and snippets.

@grohiro
Last active June 14, 2019 16:00
Show Gist options
  • Select an option

  • Save grohiro/f4bd6bd5e7721798c333cbbbcb795048 to your computer and use it in GitHub Desktop.

Select an option

Save grohiro/f4bd6bd5e7721798c333cbbbcb795048 to your computer and use it in GitHub Desktop.
Laravel, Docker, CircleCI
version: 2
jobs:
build:
docker:
# using custom image, see .circleci/images/primary/Dockerfile
- image: circleci/cci-demo-docker-primary:0.0.2
working_directory: /go/src/github.com/circleci/cci-demo-docker
steps:
- checkout
- setup_remote_docker
# This should go into custom primary image, here's only for the sake of explanation
- run:
name: Install Docker client
command: |
set -x
VER="17.03.0-ce"
curl -L -o /tmp/docker-$VER.tgz https://get.docker.com/builds/Linux/x86_64/docker-$VER.tgz
tar -xz -C /tmp -f /tmp/docker-$VER.tgz
mv /tmp/docker/* /usr/bin
# This should go into custom primary image, here's only for the sake of explanation
- run:
name: Install Docker Compose
command: |
set -x
curl -L https://github.com/docker/compose/releases/download/1.11.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
- run:
name: install dockerize
command: |
wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
environment:
DOCKERIZE_VERSION: v0.3.0
- run:
name: Build container
command: |
docker-compose -f docker-compose.ci.yml build
- run:
name: Run tests
command: |
docker-compose -f docker-compose.ci.yml up -d
docker-compose -f docker-compose.ci.yml run app php artisan config:cache --env testing
for i in `seq 1 20`
do
docker-compose -f docker-compose.ci.yml exec db_testing mysqladmin --protocol=socket -uroot -proot ping && break
echo -n
sleep 5
done
echo
docker-compose -f docker-compose.ci.yml run app php artisan migrate --force
docker-compose -f docker-compose.ci.yml run app vendor/bin/phpunit
.git/
node_modules/
vendor/
.env
.vimrc.local
bootstrap/cache/*
storage/app/*
storage/framework/cache/*
storage/framework/sessions/*
storage/framework/testing/*
storage/framework/views/*
storage/storage/logs/*
version: '3'
services:
app:
image: sandbox-laravel-testing
working_dir: /webapp/
build:
context: .
dockerfile: ./containers/app/Dockerfile
volumes:
- bootstrap_cache:/webapp/bootstrap/cache
- storage:/webapp/storage
depends_on:
- db_testing
db_testing:
image: mysql:5.7
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
volumes:
- mysql_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: laravel_testing
MYSQL_PASSWORD: laravel_testing
MYSQL_DATABASE: laravel_testing
volumes:
mysql_data:
bootstrap_cache:
storage:
FROM php:7.1-cli
RUN set -e \
&& apt-get update -y -qq \
&& apt-get install -y -qq \
build-essential \
git \
unzip \
&& apt-get autoremove -y \
&& apt-get autoclean -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN curl -O https://nodejs.org/dist/v10.16.0/node-v10.16.0-linux-x64.tar.xz \
&& tar xvf node-v10.16.0-linux-x64.tar.xz \
&& mv node-v10.16.0-linux-x64 /usr/local \
&& ln -s /usr/local/node-v10.16.0-linux-x64/bin/* /usr/local/bin/
RUN docker-php-ext-install pdo pdo_mysql
RUN mkdir -p /webapp
WORKDIR /webapp
COPY composer.* /webapp/
RUN composer install --no-autoloader
COPY package.* /webapp/
RUN npm install
COPY . /webapp/
RUN composer dump-autoload
VOLUME \
"/webapp/bootstrap/cache" \
"/webapp/node_modules" \
"/webapp/storage" \
"/webapp/vendor"
EXPOSE 3306
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment