tidying up docs #30
Workflow file for this run
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
################################################ | |
# NECESSARY GITHUB SECRETS TO SET # | |
################################################ | |
# secrets.imagename : e.g "<org>/<image>" | |
# secrets.registryuser | |
# secrets.registrypwd | |
# secrets.server : (not currently implemented) | |
################################################ | |
name: Docker Image CI | |
# Leave out specific branches so this same workflow can be used on any branch | |
on: | |
push: | |
workflow_dispatch: | |
repository_dispatch: | |
types: [ upstreamTDS ] | |
pull_request_target: | |
types: [ opened, reopened, edited, synchronize, closed] | |
jobs: | |
outputVars: | |
runs-on: ubuntu-latest | |
outputs: | |
tag: ${{ steps.set-output-vars.outputs.tag }} | |
threddsWarURL: ${{ steps.set-output-vars.outputs.threddsWarURL }} | |
steps: | |
- name: Repository Dispatch Event | |
if: ${{ github.event.action == 'upstreamTDS' }} | |
run: | | |
echo ${{ github.event.action }} | |
echo "tag=${{ github.event.client_payload.tag }}" >> $GITHUB_ENV | |
echo "threddsWarURL=${{ github.event.client_payload.threddsWarURL }}" >> $GITHUB_ENV | |
- name: Other Events | |
if: ${{ github.event.action != 'upstreamTDS' }} | |
run: | | |
echo ${{ github.event.action }} | |
tag=${{ github.ref }} && tag=${tag##*/} | |
echo "tag=${tag}" >> $GITHUB_ENV | |
echo "threddsWarURL='n/a'" >> $GITHUB_ENV | |
- name: Set output vars | |
id: set-output-vars | |
run: | | |
echo "::set-output name=tag::${{ env.tag }}" | |
echo "::set-output name=threddsWarURL::${{ env.threddsWarURL }}" | |
buildAndTest: | |
runs-on: ubuntu-latest | |
needs: outputVars | |
steps: | |
- name: Set environment variables | |
run: | | |
echo "tag=${{ needs.outputVars.outputs.tag }}" >> $GITHUB_ENV | |
echo "threddsWarURL=${{ needs.outputVars.outputs.threddsWarURL }}" >> $GITHUB_ENV | |
# Checkout the commit that triggered the workflow | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Checkout branch on upstreamTDS | |
if: ${{ github.event.action == 'upstreamTDS' }} | |
run: | | |
test $(git branch --list -r "origin/${{ env.tag }}" | head -c1 | wc -c) -ne 0 && | |
git checkout ${{ env.tag }} || | |
git checkout -b ${{ env.tag }} | |
git status | |
- name: Modify Dockerfile on upstreamTDS | |
if: ${{ github.event.action == 'upstreamTDS' }} | |
run: | | |
sed -e "s|ENV THREDDS_WAR_URL.*|ENV THREDDS_WAR_URL ${{ env.threddsWarURL }}|g" ./Dockerfile -i | |
- name: Build the Docker image | |
run: docker build --no-cache -t ${{ secrets.imagename }}:${{ env.tag }} . | |
- name: Run the container | |
run: | | |
docker run \ | |
-v $(pwd)/.github/testScripts:/testScripts \ | |
-d \ | |
-p 8080:8080 \ | |
${{ secrets.imagename }}:${{ env.tag }} | |
- name: Run test script | |
run: ./.github/testScripts/test.sh | |
- name: Push to github on upstreamTDS | |
if: ${{ github.event.action == 'upstreamTDS' }} | |
run: | | |
git config --global user.name 'Github Actions' | |
git config --global user.email 'respinoza@ucar.edu' | |
git commit --all --allow-empty -m "Update TDS" | |
git push origin ${{ env.tag }} | |
- name: Push to Dockerhub | |
if: ${{ github.event.action == 'upstreamTDS' || github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == 'true'}} | |
run: | | |
echo "Event that triggered workflow: ${{ github.event_name }}" | |
docker logout | |
echo ${{ secrets.registrypwd }} | docker login -u ${{ secrets.registryuser }} --password-stdin | |
docker push ${{ secrets.imagename }}:${{ env.tag }} && | |
{ docker logout && echo "Successfully pushed ${{ secrets.imagename }}:${{ env.tag }}"; } || | |
{ docker logout && echo "Docker push failed" && exit 1; } |