name: Docker Image CI

on:
  push:
    tags:
      - n8n@*

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - name: Get the version
      id: vars
      run: echo ::set-output name=tag::$(echo ${GITHUB_REF:14})
    - name: Set up QEMU
      uses: docker/setup-qemu-action@v1
    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v1
    - name: Login to DockerHub
      uses: docker/login-action@v1
      with:
        username: ${{ secrets.DOCKER_USERNAME }}
        password: ${{ secrets.DOCKER_PASSWORD }}
    - name: Build
      uses: docker/build-push-action@v2
      with:
        context: ./docker/images/n8n
        build-args: |
          N8N_VERSION=${{steps.vars.outputs.tag}}
        platforms: linux/amd64,linux/arm64,linux/arm/v7
        push: true
        tags: |
          ${{ secrets.DOCKER_USERNAME }}/n8n:${{ steps.vars.outputs.tag }}
          ${{ secrets.DOCKER_USERNAME }}/n8n:latest
    - name: Build (debian)
      uses: docker/build-push-action@v2
      with:
        context: ./docker/images/n8n-debian
        build-args: |
          N8N_VERSION=${{ steps.vars.outputs.tag }}
        platforms: linux/amd64,linux/arm64,linux/arm/v7
        push: true
        tags: |
          ${{ secrets.DOCKER_USERNAME }}/n8n:${{ steps.vars.outputs.tag }}-debian
          ${{ secrets.DOCKER_USERNAME }}/n8n:latest-debian
