-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (79 loc) · 2.95 KB
/
deploy.yml
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
name: Docker build
# Run if triggered by upstream release, if Dockerfile is updated, or if manually triggered
on:
repository_dispatch:
types: [post-release]
push:
paths:
- 'Dockerfile'
- 'poetry.lock'
workflow_dispatch:
inputs:
version:
description: 'Pyinaturalist version to build'
required: false
default: 'latest'
env:
DOCKERHUB_OWNER: jxcook
IMAGE_NAME: pyinaturalist-notebook
PACKAGE_NAME: pyinaturalist
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# Initial setup + login
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
# Determine pyinaturalist package version to install (either specified version or latest)
- name: Set PyPI package version
id: pypi
run: |
pip install packaging
IS_LATEST=${{ (github.event.inputs.version || 'latest') == 'latest' }}
PYPI_VERSION=$(python ${GITHUB_WORKSPACE}/pypi_version.py ${{ env.PACKAGE_NAME }})
BUILD_VERSION=$(test ${IS_LATEST}=true && echo $PYPI_VERSION || echo ${{ github.event.inputs.version}})
echo "Latest version: ${PYPI_VERSION} | Build version: ${BUILD_VERSION}"
echo "version=${BUILD_VERSION}" >> $GITHUB_OUTPUT
echo "is_latest=${IS_LATEST}" >> $GITHUB_OUTPUT
# Set Docker tags
- name: Set Docker tags
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKERHUB_OWNER }}/${{ env.IMAGE_NAME }}
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
flavor: latest=${{ steps.pypi.outputs.is_latest }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha,prefix=,format=short
type=semver,pattern={{version}},value=${{ steps.pypi.outputs.version }}
type=semver,pattern={{major}}.{{minor}},value=${{ steps.pypi.outputs.version }}
type=semver,pattern={{major}},value=${{ steps.pypi.outputs.version }}
# Build and publish image
- name: Build and publish image to Docker Hub + GitHub Containers
uses: docker/build-push-action@v6
with:
context: .
pull: true
push: true
build-args: PACKAGE_VERSION=${{ steps.pypi.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}