diff --git a/.github/workflows/build-docker-image.yaml b/.github/workflows/build-docker-image.yaml new file mode 100644 index 0000000..a391d3b --- /dev/null +++ b/.github/workflows/build-docker-image.yaml @@ -0,0 +1,53 @@ +name: Build + +on: + workflow_dispatch: + schedule: + - cron: '0 9 * * *' + push: + branches: + - main + paths-ignore: + - '**/LICENSE' + - '**/*.md' + pull_request: + paths-ignore: + - '**/LICENSE' + - '**/*.md' + +env: + DOCKER-CONTEXT: ./ + DOCKER-FILE: ./.github/Dockerfile + DOCKER-IMAGE: trainee + DOCKER-TAG: humble + +jobs: + docker: + name: Build Docker Image + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker image tag + run: echo "DOCKER_IMAGE_TAG=ghcr.io/$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')/${{ env.DOCKER-IMAGE }}:${{ env.DOCKER-TAG }}" >> $GITHUB_ENV + + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: ${{ env.DOCKER-CONTEXT }} + file: ${{ env.DOCKER-FILE }} + tags: ${{ env.DOCKER_IMAGE_TAG }} + build-args: USERNAME=runner + no-cache: true + push: false diff --git a/.github/workflows/push-docker-image.yaml b/.github/workflows/push-docker-image.yaml index 2d411b7..b399c4c 100644 --- a/.github/workflows/push-docker-image.yaml +++ b/.github/workflows/push-docker-image.yaml @@ -1,28 +1,23 @@ -name: Docker +name: Push on: workflow_dispatch: - schedule: - - cron: '0 9 * * *' - push: - branches: - - main - paths-ignore: - - '**/LICENSE' - - '**/*.md' - pull_request: - paths-ignore: - - '**/LICENSE' - - '**/*.md' + workflow_run: + workflows: ["Build"] + types: + - completed env: DOCKER-CONTEXT: ./ - DOCKER-FILE: ./Dockerfile + DOCKER-FILE: ./.github/Dockerfile + DOCKER-IMAGE: trainee + DOCKER-TAG: humble jobs: docker: - name: Build & Push Docker Image + name: Build Docker Image runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' }} steps: - uses: actions/checkout@v3 @@ -37,12 +32,15 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Set up Docker image tag + run: echo "DOCKER_IMAGE_TAG=ghcr.io/$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')/${{ env.DOCKER-IMAGE }}:${{ env.DOCKER-TAG }}" >> $GITHUB_ENV + - name: Build and push uses: docker/build-push-action@v3 with: context: ${{ env.DOCKER-CONTEXT }} file: ${{ env.DOCKER-FILE }} - tags: ghcr.io/${{ github.repository_owner }}/trainee:humble + tags: ${{ env.DOCKER_IMAGE_TAG }} build-args: USERNAME=runner no-cache: true push: true