|
9 | 9 | push: |
10 | 10 | branches: |
11 | 11 | - main |
| 12 | + release: |
| 13 | + types: |
| 14 | + - published |
12 | 15 |
|
13 | 16 | permissions: |
14 | 17 | id-token: write |
@@ -58,63 +61,48 @@ jobs: |
58 | 61 | poetry check |
59 | 62 | poetry run python ./.github/actions/verify_imports.py |
60 | 63 |
|
61 | | - docker-build: |
| 64 | + docker-build-push: |
62 | 65 | runs-on: ubuntu-latest |
| 66 | + permissions: |
| 67 | + contents: read |
| 68 | + packages: write |
| 69 | + env: |
| 70 | + REGISTRY: ghcr.io |
| 71 | + IMAGE_NAME: ${{ github.repository }} |
63 | 72 |
|
64 | 73 | steps: |
65 | | - - uses: actions/checkout@v4 |
66 | | - |
67 | 74 | - name: Set up Docker Buildx |
68 | 75 | uses: docker/setup-buildx-action@v3 |
69 | 76 |
|
70 | | - - name: Build and push Docker image |
71 | | - uses: docker/build-push-action@v5 |
| 77 | + - name: Extract build metadata |
| 78 | + id: meta |
| 79 | + uses: docker/metadata-action@v5 |
72 | 80 | with: |
73 | | - context: . |
74 | | - file: ./Dockerfile |
75 | | - tags: reactome-chatbot:${{ github.sha }} |
76 | | - outputs: type=docker,dest=/tmp/image.tar |
77 | | - |
78 | | - - uses: actions/upload-artifact@v4 |
| 81 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 82 | + tags: | |
| 83 | + type=semver,pattern={{version}} |
| 84 | + type=sha,format=short,prefix= |
| 85 | +
|
| 86 | + - name: Login to Docker registry ${{ env.REGISTRY }} |
| 87 | + if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'release' && github.event.action == 'published') |
| 88 | + uses: docker/login-action@v3 |
79 | 89 | with: |
80 | | - name: image-artifact |
81 | | - path: /tmp/image.tar |
| 90 | + registry: ${{ env.REGISTRY }} |
| 91 | + username: ${{ github.actor }} |
| 92 | + password: ${{ secrets.GITHUB_TOKEN }} |
82 | 93 |
|
83 | | - docker-push: |
84 | | - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} |
85 | | - needs: docker-build |
86 | | - runs-on: ubuntu-latest |
87 | | - |
88 | | - steps: |
89 | | - - uses: actions/download-artifact@v4 |
| 94 | + - name: Build (and push) Docker image |
| 95 | + uses: docker/build-push-action@v6 |
90 | 96 | with: |
91 | | - name: image-artifact |
92 | | - path: /tmp |
93 | | - - id: get-hash |
94 | | - run: | |
95 | | - FULL_SHA=${{ github.sha }} |
96 | | - echo "SHORT_SHA=${FULL_SHA:0:7}" >> $GITHUB_OUTPUT |
| 97 | + tags: ${{ steps.meta.outputs.tags }} |
| 98 | + labels: ${{ steps.meta.outputs.labels }} |
| 99 | + push: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'release' && github.event.action == 'published') }} |
| 100 | + outputs: type=docker,dest=/tmp/image.tar |
| 101 | + provenance: mode=max |
| 102 | + cache-from: type=gha |
| 103 | + cache-to: type=gha,mode=max |
97 | 104 |
|
98 | | - - env: |
99 | | - AWS_REGION: us-east-1 |
100 | | - uses: aws-actions/configure-aws-credentials@v4 |
101 | | - with: |
102 | | - role-to-assume: ${{ vars.AWS_ROLE }} |
103 | | - aws-region: ${{ env.AWS_REGION }} |
104 | | - |
105 | | - - id: login-ecr |
106 | | - uses: aws-actions/amazon-ecr-login@v2 |
| 105 | + - uses: actions/upload-artifact@v4 |
107 | 106 | with: |
108 | | - registry-type: public |
109 | | - |
110 | | - - env: |
111 | | - AWS_REGISTRY: ${{ steps.login-ecr.outputs.registry }} |
112 | | - AWS_REGISTRY_ALIAS: reactome |
113 | | - AWS_REPO: reactome-chatbot |
114 | | - IMG_TAG: ${{ steps.get-hash.outputs.SHORT_SHA }} |
115 | | - run: | |
116 | | - docker load --input /tmp/image.tar |
117 | | - docker image tag reactome-chatbot:${{ github.sha }} $AWS_REGISTRY/$AWS_REGISTRY_ALIAS/$AWS_REPO:$IMG_TAG |
118 | | - docker image tag reactome-chatbot:${{ github.sha }} $AWS_REGISTRY/$AWS_REGISTRY_ALIAS/$AWS_REPO:latest |
119 | | - docker push $AWS_REGISTRY/$AWS_REGISTRY_ALIAS/$AWS_REPO:$IMG_TAG |
120 | | - docker push $AWS_REGISTRY/$AWS_REGISTRY_ALIAS/$AWS_REPO:latest |
| 107 | + name: image-artifact |
| 108 | + path: /tmp/image.tar |
0 commit comments