aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/autogpt-docker-release.yml
blob: 4213c78b5c02cc70bd8edfd7e0b709749c97dc21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: AutoGPT Docker Release

on:
  release:
    types: [ published, edited ]

  workflow_dispatch:
    inputs:
      no_cache:
        type: boolean
        description: 'Build from scratch, without using cached layers'

defaults:
  run:
    working-directory: autogpts/autogpt

env:
  IMAGE_NAME: auto-gpt
  DEPLOY_IMAGE_NAME: ${{ secrets.DOCKER_USER }}/auto-gpt

jobs:
  build:
    if: startsWith(github.ref, 'refs/tags/autogpt-')
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v3

    - name: Log in to Docker hub
      uses: docker/login-action@v2
      with:
        username: ${{ secrets.DOCKER_USER }}
        password: ${{ secrets.DOCKER_PASSWORD }}

    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v2

      # slashes are not allowed in image tags, but can appear in git branch or tag names
    - id: sanitize_tag
      name: Sanitize image tag
      run: |
        tag=${raw_tag//\//-}
        echo tag=${tag#autogpt-} >> $GITHUB_OUTPUT
      env:
        raw_tag: ${{ github.ref_name }}

    - id: build
      name: Build image
      uses: docker/build-push-action@v3
      with:
        context: autogpts/autogpt
        build-args: BUILD_TYPE=release
        load: true    # save to docker images
        # push: true  # TODO: uncomment when this issue is fixed: https://github.com/moby/buildkit/issues/1555
        tags: >
          ${{ env.IMAGE_NAME }},
          ${{ env.DEPLOY_IMAGE_NAME }}:latest,
          ${{ env.DEPLOY_IMAGE_NAME }}:${{ steps.sanitize_tag.outputs.tag }}

        # cache layers in GitHub Actions cache to speed up builds
        cache-from: ${{ !inputs.no_cache && 'type=gha' || '' }},scope=autogpt-docker-release
        cache-to: type=gha,scope=autogpt-docker-release,mode=max

    - name: Push image to Docker Hub
      run: docker push --all-tags ${{ env.DEPLOY_IMAGE_NAME }}

    - name: Generate build report
      env:
        event_name: ${{ github.event_name }}
        event_ref: ${{ github.event.ref }}
        event_ref_type: ${{ github.event.ref}}
        inputs_no_cache: ${{ inputs.no_cache }}

        prod_branch: master
        dev_branch: development
        repository: ${{ github.repository }}
        base_branch: ${{ github.ref_name != 'master' && github.ref_name != 'development' && 'development' || 'master' }}

        ref_type: ${{ github.ref_type }}
        current_ref: ${{ github.ref_name }}
        commit_hash: ${{ github.sha }}
        source_url: ${{ format('{0}/tree/{1}', github.event.repository.url, github.event.release && github.event.release.tag_name || github.sha) }}

        github_context_json: ${{ toJSON(github) }}
        job_env_json: ${{ toJSON(env) }}
        vars_json: ${{ toJSON(vars) }}

      run: .github/workflows/scripts/docker-release-summary.sh >> $GITHUB_STEP_SUMMARY
      working-directory: ./
      continue-on-error: true