diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..a9250d54 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,61 @@ +name: build + +on: + push: + branches: [master] + release: + types: [published] + +env: + CI: true + CI_REGISTRY_IMAGE: crfdevs/resop + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + + - name: Login to DockerHub Registry + run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin + + - name: Get the version + id: vars + run: | + echo ::set-output name=BUILD_TAG::$(git describe --tags) + echo ::set-output name=CI_COMMIT_REF_SLUG::${GITHUB_REF#refs/*/} + + - name: Pull existing Docker image + run: | + docker pull ${CI_REGISTRY_IMAGE}:fpm-master || true + docker pull ${CI_REGISTRY_IMAGE}:nginx-master || true + + - name: Build the Docker images + run: | + docker build --pull -t ${CI_REGISTRY_IMAGE}:fpm-${CI_COMMIT_REF_SLUG} --cache-from ${CI_REGISTRY_IMAGE}:fpm-master -f docker/php-flex/Dockerfile --target withsources-fpm --build-arg BUILD_TAG=${BUILD_TAG} . + docker run --rm -v $(pwd):/host ${CI_REGISTRY_IMAGE}:fpm-${CI_COMMIT_REF_SLUG} mv -f /srv/public/build /host/public + docker build --pull -t ${CI_REGISTRY_IMAGE}:nginx-${CI_COMMIT_REF_SLUG} --cache-from ${CI_REGISTRY_IMAGE}:nginx-master -f docker/nginx/Dockerfile --target withsources . + env: + BUILD_TAG: ${{ steps.vars.outputs.BUILD_TAG }} + CI_COMMIT_REF_SLUG: ${{ steps.vars.outputs.CI_COMMIT_REF_SLUG }} + + - name: Push the latest Docker image + run: | + docker push ${CI_REGISTRY_IMAGE}:fpm-${CI_COMMIT_REF_SLUG} + docker push ${CI_REGISTRY_IMAGE}:nginx-${CI_COMMIT_REF_SLUG} + env: + CI_COMMIT_REF_SLUG: ${{ steps.vars.outputs.CI_COMMIT_REF_SLUG }} + + - name: Deploy snapshot on master + if: github.ref == 'refs/heads/master' + run: curl --request POST --form "token=${{ secrets.SNAPSHOT_DEPLOY_TOKEN }}" --form ref=master "${{ secrets.SNAPSHOT_DEPLOY_URL }}" 1>/dev/null + + - name: Push the latest Docker release image + if: github.event_name == 'release' + run: | + docker tag ${CI_REGISTRY_IMAGE}:fpm-${CI_COMMIT_REF_SLUG} ${CI_REGISTRY_IMAGE}:fpm-release-latest + docker push ${CI_REGISTRY_IMAGE}:fpm-release-latest + docker tag ${CI_REGISTRY_IMAGE}:nginx-${CI_COMMIT_REF_SLUG} ${CI_REGISTRY_IMAGE}:nginx-release-latest + docker push ${CI_REGISTRY_IMAGE}:nginx-release-latest + env: + CI_COMMIT_REF_SLUG: ${{ steps.vars.outputs.CI_COMMIT_REF_SLUG }} diff --git a/README.md b/README.md index ed9de699..191bd003 100644 --- a/README.md +++ b/README.md @@ -161,3 +161,44 @@ bin/node-tools yarn encore dev webpack-build-dev make webpack-watch-dev ``` + +## Built docker images + +Every time a new commit is pushed onto master, the following Docker images are built: + +- [crfdevs/resop:fpm-master](https://hub.docker.com/repository/docker/crfdevs/resop/tags?page=1&name=fpm) +- [crfdevs/resop:nginx-master](https://hub.docker.com/repository/docker/crfdevs/resop/tags?page=1&name=nginx) + +Every time a new release is created, the following Docker images are built: + +- [crfdevs/resop:fpm-1.1.1](https://hub.docker.com/repository/docker/crfdevs/resop/tags?page=1&name=fpm-) +- [crfdevs/resop:fpm-release-latest](https://hub.docker.com/repository/docker/crfdevs/resop/tags?page=1&name=fpm-release-latest) +- [crfdevs/resop:nginx-1.1.1](https://hub.docker.com/repository/docker/crfdevs/resop/tags?page=1&name=nginx-) +- [crfdevs/resop:nginx-release-latest](https://hub.docker.com/repository/docker/crfdevs/resop/tags?page=1&name=nginx-release-latest) + +## Usage in production + +This is an example of docker-compose.yml file with parameters you should use for production: + +```yaml +services: + nginx: + image: crfdevs/resop:nginx-release-latest + depends_on: + - fpm + environment: + - "FPM_ENDPOINT=fpm:9001" + + fpm: + image: crfdevs/resop:npm-release-latest + environment: + - INIT_DB=true # Run migrations on start + - DANGEROUSLY_LOAD_FIXTURES=false # Reset DB and load fixtures on start + - "DATABASE_URL=postgresql://:@/?serverVersion=11&charset=utf8" +``` + +If you want to initialize the DB with production data, run the following command in the fpm container: + +```bash +bin/console app:load-organizations +```