From 346d62e37edc3c0ab13e58f25debabcb1aad8a0c Mon Sep 17 00:00:00 2001 From: Ross Whitfield Date: Thu, 20 Jun 2024 13:22:34 +1000 Subject: [PATCH] Add docker publish action --- .github/workflows/publish.yml | 94 +++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..e1e89a4 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,94 @@ +name: Wheel + Docker publish + +on: + push: + branches: + - publish_build + - qa + - main + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + +jobs: + build: + + runs-on: ubuntu-latest + defaults: + run: + shell: bash -l {0} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: conda-incubator/setup-miniconda@v2 + with: + auto-update-conda: true + channels: conda-forge,defaults + mamba-version: "*" + environment-file: environment.yml + cache-environment-key: ${{ runner.os }}-env-${{ hashFiles('**/environment.yml') }} + cache-downloads-key: ${{ runner.os }}-downloads-${{ hashFiles('**/environment.yml') }} + - name: Install requirements + run: | + # --quiet should turn off progress bars to make logs more readable + conda env create + - name: Get version + id: version + run: | + conda activate livedata + echo "::set-output name=version::$(versioningit)" + + - name: Create tag version + id: tag + run: | + conda activate livedata + echo "::set-output name=tag::$(versioningit).b$(date +'%Y%m%d%H%M')" + + - name: Create latest tag version + id: latest_tag + run: | + case ${{ github.ref }} in + + refs/heads/publish_build) + echo "::set-output name=latest_tag::latest-dev" + ;; + + refs/heads/qa) + echo "::set-output name=latest_tag::latest-test" + ;; + + refs/heads/main) + echo "::set-output name=latest_tag::latest-prod" + ;; + + *) + exit 1 + ;; + + esac + + - name: Check tag names + run: | + echo ${{ steps.latest_tag.outputs.latest_tag }} + echo ${{ steps.tag.outputs.tag }} + + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push docker image + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + tags: | + ${{ env.REGISTRY }}/${{ github.repository }}/live_data_server:${{ steps.latest_tag.outputs.latest_tag }} + ${{ env.REGISTRY }}/${{ github.repository }}/live_data_server:${{ steps.tag.outputs.tag }} + push: true