43 lines
1.6 KiB
YAML
43 lines
1.6 KiB
YAML
name: Build Jtr app test image
|
|
run-name: ${{ gitea.actor }} triggered a test build for the Jtr app
|
|
on: [ push ]
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
if: gitea.ref == 'refs/heads/develop'
|
|
steps:
|
|
- uses: https://github.com/actions/checkout@v4
|
|
- uses: https://github.com/actions/setup-node@v4
|
|
with:
|
|
node-version: '20.x'
|
|
- name: "Build image"
|
|
run: |
|
|
IMAGE_NAME="git.devdisciples.com/devdisciples/jtr-app-test"
|
|
IMAGE_VERSION=$(npm pkg get version --workspaces=false | tr -d \")
|
|
VERSIONED_IMAGE_TAG="$IMAGE_NAME:$IMAGE_VERSION"
|
|
LATEST_IMAGE_TAG="$IMAGE_NAME:latest"
|
|
|
|
# Login to the registry
|
|
echo ${{ secrets.DOCKER_PASS }} | docker login git.devdisciples.com --username ${{ secrets.DOCKER_USER }} --password-stdin
|
|
|
|
# Check if the image exists.
|
|
# EXISTS = 0 if the image was found else 1.
|
|
EXISTS=$(docker manifest inspect $VERSIONED_IMAGE_TAG > /dev/null 2>&1; echo $?)
|
|
|
|
# If the image does not exist, then build it.
|
|
if [[ $EXISTS -eq 1 ]]; then
|
|
echo "Building image $VERSIONED_IMAGE_TAG"
|
|
docker build --build-arg API_URL="https://api.jtr.local" -t $VERSIONED_IMAGE_TAG -t $LATEST_IMAGE_TAG .
|
|
|
|
echo "Building image $VERSIONED_IMAGE_TAG"
|
|
docker push $VERSIONED_IMAGE_TAG
|
|
|
|
echo "Building image $LATEST_IMAGE_TAG"
|
|
docker push $LATEST_IMAGE_TAG
|
|
# Else notify the user that the image tag already exists and exit with status code 1.
|
|
else
|
|
echo "Image $VERSIONED_IMAGE_TAG already exists."
|
|
exit 1
|
|
fi
|