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
name: Push apphub image To DockerHub, and upload Websoft9 API to https://support.websoft9.com/apidocs | |
on: | |
push: | |
branches: [main] | |
paths: | |
- "docker/apphub/Dockerfile" | |
jobs: | |
build: | |
name: Build Docker image | |
runs-on: ubuntu-latest | |
env: | |
TAGS: latest | |
steps: | |
- uses: actions/checkout@v2 | |
name: Check out code | |
- name: Get version | |
run: | | |
version=$(grep -Po '(?<=LABEL version=").*?(?=")' docker/apphub/Dockerfile) | |
echo $version | |
real_version=${version%%-*} | |
echo "VERSION=$version" >> $GITHUB_ENV | |
if [ "$version" != "$real_version" ]; then | |
version_list=$version | |
else | |
IFS='.' read -ra VERSION_PARTS <<< "$real_version" | |
version_list="latest" | |
version_accumulator="" | |
for i in "${VERSION_PARTS[@]}"; do | |
if [ -z "$version_accumulator" ]; then | |
version_accumulator=$i | |
else | |
version_accumulator=$version_accumulator.$i | |
fi | |
version_list=$version_accumulator,$version_list | |
done | |
fi | |
echo "VERSION_LIST=$version_list" >> $GITHUB_ENV | |
- uses: mr-smithers-excellent/docker-build-push@v5 | |
name: Build & push Docker image | |
with: | |
image: websoft9dev/apphub | |
tags: ${{ env.VERSION_LIST }} | |
addLatest: True | |
registry: docker.io | |
dockerfile: docker/apphub/Dockerfile | |
directory: docker/apphub | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Download redoc.standalone.js | |
run: wget -O apphub/apidocs/redoc.standalone.js https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js | |
- name: Run Docker container and get openapi.json | |
run: | | |
docker run -d --name apphub -p 8080:8080 websoft9dev/apphub:${{ env.VERSION }} | |
sleep 5 | |
max_attempts=10 | |
url="http://localhost:8080/openapi.json" | |
for attempt in $(seq 1 $max_attempts); do | |
echo "Attempt #$attempt to download $url..." | |
if wget -O apphub/apidocs/openapi.json "$url"; then | |
echo "Successfully downloaded $url" | |
break | |
else | |
echo "Failed to download $url. Waiting for 5 seconds before retry..." | |
sleep 5 | |
fi | |
done | |
- name: Upload Websoft9 API to Azure | |
uses: bacongobbler/azure-blob-storage-upload@main | |
with: | |
source_dir: apphub/apidocs | |
container_name: $web | |
connection_string: ${{ secrets.Azure_blob }} | |
extra_args: '--destination-path ./apidocs' | |
overwrite: true |