From 24dd544aded3385b54abdebb4ef35b19806feb5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 27 Apr 2020 10:48:02 +0200 Subject: [PATCH] :construction_worker: Add GitHub actions for CI (#37) * :construction_worker: Try to add GitHub action for CI * :wrench: Add env vars to GitHub action * :recycle: Deduplicate and simplify build * :whale: Add Docker deploy to GitHub action * :lock: Add Docker auth for deploy * :construction_worker: Disable Travis, keep backup --- .github/workflows/deploy.yml | 44 +++++++++++++++++++ .../workflows/{main.yml => issue-manager.yml} | 2 + .github/workflows/test.yml | 42 ++++++++++++++++++ .travis.yml => backup.travis.yml | 2 +- scripts/build-push-all.sh | 2 +- scripts/build-push.sh | 6 +-- scripts/build.sh | 12 +++++ scripts/docker-login.sh | 5 +++ scripts/test.sh | 6 +-- 9 files changed, 111 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/deploy.yml rename .github/workflows/{main.yml => issue-manager.yml} (96%) create mode 100644 .github/workflows/test.yml rename .travis.yml => backup.travis.yml (91%) create mode 100644 scripts/build.sh create mode 100644 scripts/docker-login.sh diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..5fa11ef2 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,44 @@ +name: Deploy Docker Images + +on: + push: + branches: + - master + +jobs: + build: + strategy: + matrix: + image: + - name: latest + python_version: "3.8" + - name: python3.8 + python_version: "3.8" + - name: python3.7 + python_version: "3.7" + - name: python3.6 + python_version: "3.6" + - name: python3.8-alpine3.10 + python_version: "3.8" + - name: python3.7-alpine3.8 + python_version: "3.7" + - name: python3.6-alpine3.8 + python_version: "3.6" + fail-fast: true + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: "3.7" + - name: Install Dependencies + run: python3.7 -m pip install docker pytest + - name: Deploy Image + run: bash scripts/build-push.sh + env: + NAME: ${{ matrix.image.name }} + DOCKERFILE: ${{ matrix.image.dockerfile }} + PYTHON_VERSION: ${{ matrix.image.python_version }} + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} diff --git a/.github/workflows/main.yml b/.github/workflows/issue-manager.yml similarity index 96% rename from .github/workflows/main.yml rename to .github/workflows/issue-manager.yml index 0e9450c4..cd5d7a03 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/issue-manager.yml @@ -1,3 +1,5 @@ +name: Issue Manager + on: schedule: - cron: "0 0 * * *" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..901b7637 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,42 @@ +name: Test Docker Images + +on: + push: + pull_request: + types: [opened, synchronize] + +jobs: + build: + strategy: + matrix: + image: + - name: latest + python_version: "3.8" + - name: python3.8 + python_version: "3.8" + - name: python3.7 + python_version: "3.7" + - name: python3.6 + python_version: "3.6" + - name: python3.8-alpine3.10 + python_version: "3.8" + - name: python3.7-alpine3.8 + python_version: "3.7" + - name: python3.6-alpine3.8 + python_version: "3.6" + fail-fast: true + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: "3.7" + - name: Install Dependencies + run: python3.7 -m pip install docker pytest + - name: Test Image + run: bash scripts/test.sh + env: + NAME: ${{ matrix.image.name }} + DOCKERFILE: ${{ matrix.image.dockerfile }} + PYTHON_VERSION: ${{ matrix.image.python_version }} diff --git a/.travis.yml b/backup.travis.yml similarity index 91% rename from .travis.yml rename to backup.travis.yml index 6b6dae94..fa30e2ce 100644 --- a/.travis.yml +++ b/backup.travis.yml @@ -12,7 +12,7 @@ services: - docker env: - - NAME='latest' DOCKERFILE='python3.8' PYTHON_VERSION='3.8' + - NAME='latest' PYTHON_VERSION='3.8' - NAME='python3.8' PYTHON_VERSION='3.8' - NAME='python3.7' PYTHON_VERSION='3.7' - NAME='python3.6' PYTHON_VERSION='3.6' diff --git a/scripts/build-push-all.sh b/scripts/build-push-all.sh index e54d3f10..a18cab71 100644 --- a/scripts/build-push-all.sh +++ b/scripts/build-push-all.sh @@ -2,6 +2,6 @@ set -e -echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin +bash scripts/docker-login.sh BUILD_PUSH=1 python scripts/process_all.py diff --git a/scripts/build-push.sh b/scripts/build-push.sh index 95f11d94..8eed5374 100644 --- a/scripts/build-push.sh +++ b/scripts/build-push.sh @@ -5,11 +5,11 @@ set -e use_tag="tiangolo/uvicorn-gunicorn:$NAME" use_dated_tag="${use_tag}-$(date -I)" -DOCKERFILE=${DOCKERFILE-$NAME} - -docker build -t "$use_tag" --file "./docker-images/${DOCKERFILE}.dockerfile" "./docker-images/" +bash scripts/build.sh docker tag "$use_tag" "$use_dated_tag" +bash scripts/docker-login.sh + docker push "$use_tag" docker push "$use_dated_tag" diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100644 index 00000000..19ab2396 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -e + +use_tag="tiangolo/uvicorn-gunicorn:$NAME" + +DOCKERFILE="$NAME" + +if [ "$NAME" == "latest" ] ; then + DOCKERFILE="python3.8" +fi + +docker build -t "$use_tag" --file "./docker-images/${DOCKERFILE}.dockerfile" "./docker-images/" diff --git a/scripts/docker-login.sh b/scripts/docker-login.sh new file mode 100644 index 00000000..d872c893 --- /dev/null +++ b/scripts/docker-login.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -e + +echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin diff --git a/scripts/test.sh b/scripts/test.sh index be0a0440..693467a2 100644 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,9 +1,5 @@ #!/usr/bin/env bash set -e -use_tag="tiangolo/uvicorn-gunicorn:$NAME" - -DOCKERFILE=${DOCKERFILE-$NAME} - -docker build -t "$use_tag" --file "./docker-images/${DOCKERFILE}.dockerfile" "./docker-images/" +bash scripts/build.sh pytest tests