Skip to content

Commit

Permalink
Merge pull request #1 from jennydaman/master
Browse files Browse the repository at this point in the history
Use Github Actions
  • Loading branch information
jennydaman authored Jul 7, 2021
2 parents 9c6e063 + 35ff33f commit da61c7f
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 58 deletions.
156 changes: 156 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# Automatically build multi-architectural tagged container images and push them to DockerHub
# https://github.com/FNNDSC/cookiecutter-chrisapp/wiki/Automatic-Builds
#
# - targeted platforms: x86_64, PowerPC64, ARM64
# - master is built as fnndsc/pl-lungct:latest
# - tagged commits are built as fnndsc/pl-lungct:<tag>
# - tagged commits are also uploaded to chrisstore.co
#
# In order to use this workflow, see
# https://github.com/FNNDSC/cookiecutter-chrisapp/wiki/Automatic-Builds#steps-to-enable

name: ci

on:
push:
# we have to guess what the name of the default branch is
branches: [ master, main, trunk ]
tags: [ '**' ]
pull_request:
branches: [ master, main, trunk ]
release:
types: [ created ]

jobs:
test:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: build
run: docker build -t "${GITHUB_REPOSITORY,,}" .
- name: nose tests
run: docker run "${GITHUB_REPOSITORY,,}" nosetests

publish:
if: github.event_name == 'push' || github.event_name == 'release'
runs-on: ubuntu-20.04

# we want to both push the build to DockerHub, but also
# keep a local copy so that we can run
#
# docker run fnndsc/pl-lungct lungct --json > App.json
#
# buildx currently does not support multiple output locations,
# neither can multi-architectural builds be loaded into docker.
# Here we use a local registry to cache the build.
services:
registry:
image: registry:2
ports:
- 5000:5000

steps:
- name: Get git tag
id: git_info
if: startsWith(github.ref, 'refs/tags/')
run: echo "::set-output name=tag::${GITHUB_REF##*/}"
- name: Decide image tag name
id: determine
env:
git_tag: ${{ steps.git_info.outputs.tag }}
run: |
repo="${GITHUB_REPOSITORY,,}" # to lower case
# if build triggered by tag, use tag name
tag="${git_tag:-latest}"
dock_image=$repo:$tag
echo $dock_image
echo "::set-output name=dock_image::$dock_image"
echo "::set-output name=repo::$repo"
- uses: actions/checkout@v2

# QEMU is for emulating non-x86_64 platforms
- uses: docker/setup-qemu-action@v1
# buildx is the next-generation docker image builder
- uses: docker/setup-buildx-action@v1
with:
driver-opts: network=host
# save some time during rebuilds
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
id: dockerhub_login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Build and push
uses: docker/build-push-action@v2
id: docker_build
with:
context: .
file: ./Dockerfile
tags: |
${{ steps.determine.outputs.dock_image }}
localhost:5000/${{ steps.determine.outputs.dock_image }}
platforms: linux/amd64,linux/ppc64le,linux/arm64
push: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Get plugin meta
id: pluginmeta
run: |
repo=${{ steps.determine.outputs.repo }}
dock_image=${{ steps.determine.outputs.dock_image }}
docker pull localhost:5000/$dock_image
docker tag localhost:5000/$dock_image $dock_image
script=$(docker inspect --format '{{ (index .Config.Cmd 0) }}' $dock_image)
json="$(docker run --rm $dock_image $script --json)"
jq <<< "$json" # pretty print in log
echo "::set-output name=json::$json"
echo "::set-output name=title::$(jq -r '.title' <<< "$json")"
- name: Update DockerHub description
uses: peter-evans/dockerhub-description@v2
continue-on-error: true # it is not crucial that this works
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
short-description: ${{ steps.pluginmeta.outputs.title }}
readme-filepath: ./README.rst
repository: ${{ steps.determine.outputs.repo }}

- name: Upload to ChRIS Store
if: "!endsWith(steps.determine.outputs.dock_image, ':latest')"
run: |
repo=${{ steps.determine.outputs.repo }}
dock_image=${{ steps.determine.outputs.dock_image }}
descriptor_file=$(mktemp --suffix .json)
cat > $descriptor_file <<< "${{ steps.pluginmeta.outputs.json }}"
res=$(
curl -s -u "${{ secrets.CHRIS_STORE_USER }}" "https://chrisstore.co/api/v1/plugins/" \
-F "name=$(sed 's/^.*\///' <<< $repo)" \
-F "dock_image=$dock_image" \
-F "descriptor_file=@$descriptor_file" \
-F "public_repo=https://github.com/${{ github.repository }}"
)
success=$?
if [ "$success" = "0" ]; then
href="$(jq -r '.collection.items[0].href' <<< "$res")"
echo $href
echo "::set-output name=pluginurl::$href"
else
echo "::error ::Failed upload to ChRIS Store"
echo "$res"
exit $success
fi
50 changes: 6 additions & 44 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,50 +1,12 @@
# Docker file for lungct ChRIS plugin app
#
# Build with
#
# docker build -t <name> .
#
# For example if building a local version, you could do:
#
# docker build --build-arg UID=$UID -t local/pl-lungct .
#
# In the case of a proxy (located at 192.168.13.14:3128), do:
#
# export PROXY=http://192.168.13.14:3128
# docker build --build-arg http_proxy=$PROXY --build-arg UID=$UID -t local/pl-lungct .
#
# To run an interactive shell inside this container, do:
#
# docker run -ti --entrypoint /bin/bash local/pl-lungct
#
# To pass an env var HOST_IP to container, do:
#
# docker run -ti -e HOST_IP=$(ip route | grep -v docker | awk '{if(NF==11) print $9}') --entrypoint /bin/bash local/pl-lungct
#
# To debug from within a container:
#
# docker run -ti -v $(pwd)/lungct:/usr/local/lib/python3.8/dist-packages/lungct -v $(pwd)/out:/outgoing local/pl-lungct lungct /outgoing
#

FROM fnndsc/ubuntu-python3:latest
FROM python:3.9.1-slim-buster
LABEL MAINTAINER="dev@babymri.org"

# Pass a UID on build command line (see above) to set internal UID
ARG UID=1001
ENV UID=$UID DEBIAN_FRONTEND=noninteractive

WORKDIR /usr/local/src
COPY . .
RUN pip --disable-pip-version-check install . \
&& useradd -u $UID -ms /bin/bash localuser \
&& apt update \
&& apt-get install -y sudo \
&& echo "localuser:localuser" | chpasswd \
&& addgroup localuser sudo \
&& echo "localuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

# Start as user localuser
# USER localuser
COPY requirements.txt .
RUN ["pip", "install", "-r", "requirements.txt"]

COPY . .
RUN ["pip", "install", "."]

WORKDIR /usr/local/bin
CMD ["lungct", "--help"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017-2020 FNNDSC / BCH
Copyright (c) 2017-2021 FNNDSC / BCH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 8 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
pl-lungct
================================

.. image:: https://travis-ci.org/FNNDSC/lungct.svg?branch=master
:target: https://travis-ci.org/FNNDSC/lungct
.. image:: https://img.shields.io/docker/v/fnndsc/pl-lungct?sort=semver
:target: https://hub.docker.com/r/fnndsc/pl-lungct

.. image:: https://img.shields.io/github/license/fnndsc/pl-lungct
:target: https://github.com/FNNDSC/pl-lungct/blob/master/LICENSE

.. image:: https://github.com/FNNDSC/pl-lungct/workflows/ci/badge.svg
:target: https://github.com/FNNDSC/pl-lungct/actions

.. image:: https://img.shields.io/badge/python-3.8%2B-blue.svg
:target: https://github.com/FNNDSC/pl-lungCT/blob/master/setup.py

.. contents:: Table of Contents

Expand Down
13 changes: 5 additions & 8 deletions lungct/lungct.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from os.path import abspath, basename, isdir
from distutils.dir_util import copy_tree
import shutil
import pudb
import sys
import time
import glob
Expand Down Expand Up @@ -175,13 +174,11 @@ def run(self, options):
print(Gstr_title)
print('Version: %s' % self.get_version())

if len(options.dir):
print("Copying tree %s..." % options.dir)
copy_tree(options.dir, options.outputdir)
sys.exit(0)
else:
print("No directory specified and no copy performed.")
sys.exit(1)
if not isdir(options.dir):
raise ValueError("No directory specified and no copy performed.")

print("Copying tree %s..." % options.dir)
copy_tree(options.dir, options.outputdir)

def show_man_page(self):
"""
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
chrisapp~=3.0.0rc2
nose~=1.3.7
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
author_email = 'dev@babyMRI.org',
url = 'http://wiki',
packages = ['lungct', 'data'],
install_requires = ['chrisapp~=2.0.0', 'pudb'],
install_requires = ['chrisapp'],
test_suite = 'nose.collector',
tests_require = ['nose'],
license = 'MIT',
Expand Down

0 comments on commit da61c7f

Please sign in to comment.