-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated Dockerfile, created actions, and updated the cli
- Loading branch information
romer8
committed
May 1, 2024
1 parent
c9adc12
commit 7e819b5
Showing
4 changed files
with
219 additions
and
28 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
# Based on kizbitz/dockerhub-v2-api-organization.sh at https://gist.github.com/kizbitz/175be06d0fbbb39bc9bfa6c0cb0d4721 | ||
|
||
# Example for the Docker Hub V2 API | ||
# Returns all images and tags associated with a Docker Hub organization account. | ||
# Requires 'jq': https://stedolan.github.io/jq/ | ||
|
||
# set username, password, and organization | ||
UNAME=$1 | ||
UPASS=$2 | ||
ORG=$3 | ||
REPO=$4 | ||
MAX_IMAGE=$5 | ||
# ------- | ||
|
||
set -e | ||
|
||
# get token | ||
echo "Retrieving token ..." | ||
TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'${UNAME}'", "password": "'${UPASS}'"}' https://hub.docker.com/v2/users/login/ | jq -r .token) | ||
|
||
# get list of repositories | ||
IMAGE_TAGS=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${ORG}/${REPO}/tags/?page_size=300 | jq -r '.results | sort_by(.last_updated) | reverse[] | .name') | ||
count=0 | ||
echo ${IMAGE_TAGS} | ||
for j in ${IMAGE_TAGS} | ||
do | ||
count_all=$((count_all + 1)) | ||
if [[ ${j} == *"dev_"* ]]; then | ||
count=$((count + 1)) | ||
# Keep the first max_image. | ||
if [ ${MAX_IMAGE} -lt ${count} ]; then | ||
echo -n " - ${j} ... " | ||
curl -X DELETE -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${ORG}/${REPO}/tags/${j}/ | ||
echo "DELETED" | ||
fi | ||
fi | ||
done |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
name: build_push_dev_image | ||
|
||
on: | ||
push: | ||
branches: | ||
- '*' | ||
|
||
env: | ||
DOCKER_HUB_ORG: gioelkin | ||
DOCKER_REPO: tethys-ngiab | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
# build image | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
submodules: 'true' | ||
|
||
# Checks-out the hydrocompute extra submodule | ||
- name: checkout Hydrocompute submodule | ||
run: | | ||
cd apps/tethysapp-hydrocompute/tethysapp/hydrocompute/public/HydroCompute && git submodule update --force --init --recursive --remote | ||
- name: Set Tag | ||
run: | | ||
echo "TAG=dev_${GITHUB_SHA}" >> $GITHUB_ENV | ||
echo "TAG_LATEST=dev_latest" >> $GITHUB_ENV | ||
- name: Test Tag | ||
run: | | ||
echo $TAG | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKER_BUILDER_USERNAME }} | ||
password: ${{ secrets.DOCKER_BUILDER_TOKEN }} | ||
|
||
- name: Build and push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
push: true | ||
tags: | | ||
${{ env.DOCKER_HUB_ORG }}/${{ env.DOCKER_REPO }}:${{ env.TAG }} | ||
${{ env.DOCKER_HUB_ORG }}/${{ env.DOCKER_REPO }}:${{ env.TAG_LATEST }} | ||
cache-from: type=registry,ref=${{ env.DOCKER_HUB_ORG }}/${{ env.DOCKER_REPO }}-dev-cache:latest | ||
cache-to: type=registry,ref=${{ env.DOCKER_HUB_ORG }}/${{ env.DOCKER_REPO }}-dev-cache:latest,mode=max | ||
|
||
cleanup: | ||
needs: [build] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: only keeps the first 5 image | ||
run: | | ||
echo "TAG=dev_${GITHUB_SHA}" >> $GITHUB_ENV | ||
echo $TAG | ||
. .github/scripts/clean_up_docker_hub.sh '${{ secrets.DOCKER_BUILDER_USERNAME }}' '${{ secrets.DOCKER_BUILDER_TOKEN }}' '${{ env.DOCKER_HUB_ORG }}' '${{ env.DOCKER_REPO }}' '${{ env.MAX_NUMBER_IMAGE }}' |
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
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