Skip to content

Commit 2980942

Browse files
committed
ghcr push in github actions
1 parent bb9c102 commit 2980942

1 file changed

Lines changed: 36 additions & 48 deletions

File tree

.github/workflows/ci.yml

Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
push:
1010
branches:
1111
- main
12+
release:
13+
types:
14+
- published
1215

1316
permissions:
1417
id-token: write
@@ -58,63 +61,48 @@ jobs:
5861
poetry check
5962
poetry run python ./.github/actions/verify_imports.py
6063
61-
docker-build:
64+
docker-build-push:
6265
runs-on: ubuntu-latest
66+
permissions:
67+
contents: read
68+
packages: write
69+
env:
70+
REGISTRY: ghcr.io
71+
IMAGE_NAME: ${{ github.repository }}
6372

6473
steps:
65-
- uses: actions/checkout@v4
66-
6774
- name: Set up Docker Buildx
6875
uses: docker/setup-buildx-action@v3
6976

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
7280
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
7989
with:
80-
name: image-artifact
81-
path: /tmp/image.tar
90+
registry: ${{ env.REGISTRY }}
91+
username: ${{ github.actor }}
92+
password: ${{ secrets.GITHUB_TOKEN }}
8293

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
9096
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
97104

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
107106
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

Comments
 (0)