diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 30b04215db..908fad6fcd 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -9,6 +9,7 @@ on: # Publish `vfrinx2.0.3` tags as releases. tags: - vfrinx2* + workflow_dispatch: env: # TODO: Change variable to your image's name. @@ -17,9 +18,21 @@ env: jobs: # Push image to GitHub Packages. # See also https://docs.docker.com/docker-hub/builds/ - push-v2: + build-image-v2: runs-on: ubuntu-latest - if: github.event_name == 'push' + + services: + postgres: + image: postgres + ports: + - 5432:5432 + env: + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 steps: - uses: actions/checkout@v2 @@ -28,44 +41,60 @@ jobs: submodules: recursive - name: Build image - run: docker build . --file docker/server/Dockerfile --tag $IMAGE_NAME --build-arg git_commit=$(git rev-parse HEAD) + run: docker build . --file docker/server/Dockerfile --tag $IMAGE_NAME:latest --build-arg git_commit=$(git rev-parse HEAD) - name: Log into docker hub run: echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin - - name: Push image + - name: Inspect latest image + run: docker image inspect $IMAGE_NAME:latest + + # - name: Push latest image + # run: docker push $IMAGE_NAME:latest + + - name: Get the version + if: startsWith(github.ref, 'refs/tags/v') + id: get_version + run: echo ::set-output name=VERSION::$(echo $GITHUB_REF | cut -d / -f 3 | sed -e 's/^vfrinx//') + + - name: Push release image + if: startsWith(github.ref, 'refs/tags/v') + run: docker tag $IMAGE_NAME:latest $IMAGE_NAME:${{ steps.get_version.outputs.VERSION }} + + - name: Inspect release image + if: startsWith(github.ref, 'refs/tags/v') + run: docker image inspect $IMAGE_NAME:${{ steps.get_version.outputs.VERSION }} + + # - name: Push release image + # run: docker push $IMAGE_ID:${{ steps.get_version.outputs.VERSION }} + + + - name: Run conductor image + run: docker run -d --network "$(docker network ls --filter type=custom --format '{{ .Name }}')" --publish 8080:8080 $IMAGE_NAME:latest + + - name: Get conductor openapi spec + run: sleep 15 && curl http://localhost:8080/v3/api-docs -o openapi.json + + - name: Check out swagger_docs branch + uses: actions/checkout@v4 + with: + ref: swagger_docs + path: swagger_docs + fetch-depth: 2 + + - name: Commit report run: | - IMAGE_ID=$IMAGE_NAME - - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - - # Strip git ref prefix from version - VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') - - # Strip "v" prefix from tag name - [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^vfrinx//') - - # Use Docker `latest` tag convention - [ "$VERSION" == "master" ] && VERSION=latest - - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - - docker tag $IMAGE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION - - # Add latest tag if we are on master and github.ref points to a tag - if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then - MASTER=$(git show-ref --hash origin/master) - echo "master: $MASTER" - HEAD=$(git rev-parse HEAD) - echo "head: $HEAD" - echo "github.ref ${{ github.ref }}" - if [[ $MASTER == $HEAD ]]; then - VERSION=latest - echo VERSION=$VERSION - docker tag $IMAGE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION - fi - fi + git_hash=$(git rev-parse --short "$GITHUB_SHA") + git_branch=${GITHUB_REF#refs/heads/} + + cp openapi.json swagger_docs/latest.json + pushd swagger_docs || exit 1 + git config -l --show-scope + git config --global user.email "support@frinx.io" + git config --global user.name "FRINXrepo" + git add latest.json + git commit -am "Updated swagger for ${git_branch}/${git_hash}" + popd + + - name: Setup upterm session + uses: lhotari/action-upterm@v1 \ No newline at end of file