Upload model to DockerHub #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Upload model to DockerHub | |
on: | |
workflow_dispatch: | |
workflow_run: | |
workflows: ["Upload model to S3"] | |
types: | |
- completed | |
jobs: | |
upload_model_to_dockerhub: | |
if: ${{ github.repository != 'ersilia-os/eos-template' && github.event.workflow_run.conclusion == 'success' }} | |
runs-on: ubuntu-latest | |
steps: | |
# https://github.com/docker/setup-qemu-action | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v1 | |
# https://github.com/docker/setup-buildx-action | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v1 | |
# log in to dockerhub | |
- name: Login to Docker Hub | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Checkout persist credentials | |
uses: actions/checkout@master | |
with: | |
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token | |
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo | |
lfs: 'true' | |
- name: Generate the Dockerfile | |
id: generate-dockerfile | |
env: | |
REPO_NAME: ${{ github.event.repository.name }} | |
run: | | |
wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/place_a_dockerfile_in_current_eos_repo.py | |
python -m pip install requests | |
python place_a_dockerfile_in_current_eos_repo.py $REPO_NAME | |
- name: Build and push | |
id: buildMultiple | |
continue-on-error: true | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ersiliaos/${{ github.event.repository.name }}:latest | |
- name: Set build failure output | |
id: buildCheck | |
run: | | |
if [[ "${{ steps.buildMultiple.outcome }}" == "failure" ]]; then | |
echo "::set-output name=failed::true" | |
echo "AMD64" > arch.txt | |
else | |
echo "::set-output name=failed::false" | |
echo "AMD64,ARM64" > arch.txt | |
fi | |
- name: Build only for Linux/amd64 | |
id: buildSingle | |
if: steps.buildCheck.outputs.failed == 'true' | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
platforms: linux/amd64 | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ersiliaos/${{ github.event.repository.name }}:latest | |
- name: Update Metadata JSON file with DockerHub info | |
id: UpdateMetadata | |
run: | | |
mv Dockerfile_legacy Dockerfile | |
python3 -c " | |
import json | |
with open('metadata.json', 'r') as f: | |
data = json.load(f) | |
print(data) | |
with open('arch.txt', 'r') as f: | |
arch = f.read().rstrip() | |
arch = arch.split(',') | |
data['DockerHub'] = 'https://hub.docker.com/r/ersiliaos/{0}'.format(data['Identifier']) | |
data['Docker Architecture'] = arch | |
with open('metadata.json', 'w') as f: | |
json.dump(data, f, indent=4) | |
" | |
rm arch.txt | |
rm place_a_dockerfile_in_current_eos_repo.py | |
- name: Commit and push changes done to the Metadata JSON file | |
uses: actions-js/push@156f2b10c3aa000c44dbe75ea7018f32ae999772 # pin@v1.4 | |
with: | |
author_name: "ersilia-bot" | |
author_email: "ersilia-bot@users.noreply.github.com" | |
message: "updating metadata [skip ci]" | |
repository: "ersilia-os/${{ github.event.repository.name }}" | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
amend: true | |
force: true | |
- name: Add conda to system path | |
run: echo $CONDA/bin >> $GITHUB_PATH | |
- name: Source conda | |
run: source $CONDA/etc/profile.d/conda.sh | |
- name: Set Python to 3.10.10 | |
run: | |
conda install -y python=3.10.10 | |
- name: Install dependencies | |
run: | | |
source activate | |
conda init | |
conda install git-lfs -c conda-forge | |
git-lfs install | |
conda install gh -c conda-forge | |
- name: Install ersilia | |
run: | | |
source activate | |
python --version | |
echo "After conda init" | |
conda init | |
python -m pip install git+https://github.com/ersilia-os/ersilia.git | |
- name: Update metadata to AirTable | |
id: update-metadata-to-airtable | |
env: | |
USER_NAME: ${{ github.repository_owner }} | |
BRANCH: "main" | |
REPO_NAME: ${{ github.event.repository.name }} | |
AIRTABLE_API_KEY: ${{ secrets.AIRTABLE_API_KEY }} | |
run: | | |
source activate | |
echo "Updating metadata to AirTable looking at owner: $USER_NAME" | |
wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/update_metadata_to_airtable.py | |
python3 update_metadata_to_airtable.py $USER_NAME $REPO_NAME $BRANCH $AIRTABLE_API_KEY | |
rm update_metadata_to_airtable.py | |
- name: Update README file | |
id: update-readme-file | |
env: | |
MODEL_ID: ${{ github.event.repository.name }} | |
run: | | |
source activate | |
echo "Updating README file with AirTable metadata for model: $MODEL_ID" | |
wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/update_readme_from_airtable.py | |
python3 update_readme_from_airtable.py $MODEL_ID . | |
rm update_readme_from_airtable.py | |
less README.md | |
- name: Commit and push changes done to the README file | |
uses: actions-js/push@156f2b10c3aa000c44dbe75ea7018f32ae999772 # pin@v1.4 | |
with: | |
author_name: "ersilia-bot" | |
author_email: "ersilia-bot@users.noreply.github.com" | |
message: "updating readme [skip ci]" | |
repository: "ersilia-os/${{ github.event.repository.name }}" | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
amend: true | |
force: true | |
- name: Docker Hub Description | |
uses: peter-evans/dockerhub-description@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
repository: ersiliaos/${{ github.event.repository.name }} | |
short-description: "Ersilia Model Hub Identifier: ${{ github.event.repository.name }}" |