name: Docker Image CI on: push: branches: [ master ] pull_request: branches: [ master ] schedule: - cron: '0 5 * * 3' jobs: build: runs-on: ubuntu-latest env: DH_REGISTRY: docker.io IMAGE_NAME: ${{ github.repository }} REPOSITORY: ${{ github.event.repository.name }} DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} permissions: contents: read packages: write steps: - name: Checkout repository uses: actions/checkout@v2 - name: Provide default tag username if: ${{ env.DOCKER_USERNAME == '' }} run: | echo "DOCKER_USERNAME=remote" >> $GITHUB_ENV - name: determine deployment if: github.ref == 'refs/heads/master' && ( github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' ) run: echo "DEPLOY=true" >> $GITHUB_ENV - name: Log in to Docker Hub uses: docker/login-action@v1 if: env.DEPLOY == 'true' with: registry: ${{ env.DH_REGISTRY }} username: ${{ env.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@v3 with: images: ${{ env.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }} tags: type=raw,value=latest - name: Push to Docker Hub uses: docker/build-push-action@v2 with: push: ${{ env.DEPLOY }} context: . tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }}