-
Notifications
You must be signed in to change notification settings - Fork 1
45 lines (35 loc) · 1.44 KB
/
build-and-push.yaml
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
name: Build and Push Docker Images
on:
push:
branches: [ "master" ]
workflow_dispatch:
env:
IMAGE_NAME: mlmodelscope-api
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
REGISTRY_USER: ${{ github.actor }}
REGISTRY_PASSWORD: ${{ github.token }}
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Log in to GHCR
run: echo "${{ env.REGISTRY_PASSWORD }}" | docker login ${{ env.IMAGE_REGISTRY }} -u ${{ env.REGISTRY_USER }} --password-stdin
- name: Build and Tag Docker Image
run: ./scripts/build-container.sh python_api ${{ github.run_number }} ${{ env.IMAGE_REGISTRY }}
- name: Push to GHCR
run: |
docker push ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}-python_api:${{ github.run_number }}
docker push ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}-python_api:latest
- name: Print image URL
run: echo "Image pushed to ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}-python_api:${{ github.run_number }} and ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}-python_api:latest"