Skip to content

Commit

Permalink
Merge pull request #202 from crf-devs/github_build_action
Browse files Browse the repository at this point in the history
Add build workflow
  • Loading branch information
mRoca authored Apr 2, 2020
2 parents 8c52cb3 + a54ebaa commit d4afbc1
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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 }}
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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://<USER>:<PASSWORD>@<URL>/<DB>?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
```

0 comments on commit d4afbc1

Please sign in to comment.