Skip to content

Commit

Permalink
Merge pull request #59 from classtranscribe/angrave-patch-2
Browse files Browse the repository at this point in the history
Action to Create and push platform base docker image
  • Loading branch information
angrave authored Oct 26, 2023
2 parents 0ee38b1 + bd17862 commit 5f7c892
Showing 1 changed file with 114 additions and 0 deletions.
114 changes: 114 additions & 0 deletions .github/workflows/platform
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: Docker

# This will run when: requirements-platform.txt or Dockerfile-platform' are changed
#
# To be able to push to dockerhub, this execpts the following
# secrets to be set in the project:
# - DOCKERHUB_USERNAME : username that can push to the org
# - DOCKERHUB_PASSWORD : password asscoaited with the username
on:
push:
paths:
- 'requirements-platform.txt'
- 'Dockerfile-platform'
- '.github/workflows/platform.yml'

branches:
- main
- staging
- expt

pull_request:
# Trigger the workflow on release activity
release:
# Only use the types keyword to narrow down the activity types that will trigger your workflow.
types:
- published
- edited
- created

# Certain actions will only run when this is the main repo.
env:
MAIN_REPO: classtranscribe/pyapi
DOCKERHUB_ORG: classtranscribe

jobs:
docker:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
name:
- ct-python-platform
include:
- name: ct-python-platform
FOLDER: .
IMAGE: ct-python-platform

steps:
- uses: actions/checkout@v2

# calculate some variables that are used later
- name: github branch
run: |
if [ "${{ github.event.release.target_commitish }}" != "" ]; then
BRANCH="${{ github.event.release.target_commitish }}"
else
BRANCH=${GITHUB_REF##*/}
fi
echo "GITHUB_BRANCH=${BRANCH}" >> $GITHUB_ENV

# Commit was for main/release branch, build a new version
if [ "$BRANCH" == "master" -o "$BRANCH" == "main" ]; then
version="$(cat gui/package.json | jq -r .version)"
echo "VERSION=$(version)" >> $GITHUB_ENV
tags="latest"
oldversion=""
while [ "${oldversion}" != "${version}" ]; do
oldversion="${version}"
tags="${tags},${version}"
version=${version%.*}
done
echo "TAGS=${tags}" >> $GITHUB_ENV
else
echo "VERSION=$BRANCH" >> $GITHUB_ENV
echo "TAGS=$BRANCH" >> $GITHUB_ENV
fi

# build the docker image, this will always run to make sure
# the Dockerfile still works.
- name: Build image
uses: elgohr/[email protected]
env:
BRANCH: ${{ env.GITHUB_BRANCH }}
VERSION: ${{ env.VERSION }}
BUILDNUMBER: ${{ github.run_number }}
GITSHA1: ${{ github.sha }}
with:
registry: docker.pkg.github.com
name: ${{ github.repository_owner }}/${{ github.event.repository.name }}/${{ matrix.IMAGE }}
dockerfile: Dockerfile-platform
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
context: ${{ matrix.FOLDER }}
tags: "${{ env.TAGS }}"
buildargs: BRANCH,VERSION,BUILDNUMBER,GITSHA1
no_push: true

# this will publish to dockerhub
- name: Publish to Docker Hub
if: github.event_name != 'pull_request' && github.repository == env.MAIN_REPO
uses: elgohr/[email protected]
env:
BRANCH: ${{ env.GITHUB_BRANCH }}
VERSION: ${{ env.VERSION }}
BUILDNUMBER: ${{ github.run_number }}
GITSHA1: ${{ github.sha }}
with:
name: ${{ env.DOCKERHUB_ORG }}/${{ matrix.IMAGE }}
dockerfile: Dockerfile-platform
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
context: ${{ matrix.FOLDER }}
tags: "${{ env.TAGS }}"
buildargs: BRANCH,VERSION,BUILDNUMBER,GITSHA1

0 comments on commit 5f7c892

Please sign in to comment.