diff --git a/.github/workflows/build-docker.yaml b/.github/workflows/build-docker.yaml index 4b267194..db1ea7f5 100644 --- a/.github/workflows/build-docker.yaml +++ b/.github/workflows/build-docker.yaml @@ -1,40 +1,50 @@ -name: Docker Image +name: democracy-app.de-server/ Build and Push Docker Image on: - - push + push: + branches: + - 'master' + tags: + - 'v*' + pull_request: + branches: + - 'master' jobs: - build: - name: Build Docker + push: runs-on: ubuntu-latest + environment: docker steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 + - name: Docker meta + id: meta + uses: docker/metadata-action@v3 with: - submodules: true - - - name: Extract branch name - shell: bash - run: echo "##[set-output name=branch;]$(echo dev)" - id: extract_branch - - # - name: Extract branch name - # shell: bash - # run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" - # id: extract_branch - - - name: Read package.json - uses: tyankatsu0105/read-package-version-actions@v1 - id: package-version - - - name: Extract repository name - shell: bash - run: echo "##[set-output name=REPOSITORY_NAME;]$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}' | sed -e "s/:refs//")" - id: extract_repository - - - uses: docker/build-push-action@v1 + images: democracy/democracy-server + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + - 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 + if: github.event_name != 'pull_request' + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 with: - username: ${{ github.actor }} - password: ${{ github.token }} - registry: docker.pkg.github.com - repository: ${{ github.repository }}/${{ steps.extract_repository.outputs.REPOSITORY_NAME }} - tags: ${{ steps.package-version.outputs.version }}-${{ steps.extract_branch.outputs.branch }} + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }}