Skip to content

feat: healthcheck

feat: healthcheck #94

# Copyright (c) 2023 Maxim [maxirmx] Samsonov (https:#sw.consulting)
# This file is a part of TrustVPN
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
name: build-and-push
on:
push:
branches: [ main ]
paths-ignore:
- '**.adoc'
- '**.md'
tags: [ 'v*' ]
pull_request:
workflow_dispatch:
concurrency:
group: '${{ github.workflow }}-${{ github.job }}-${{ github.head_ref || github.ref_name }}'
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Start the application
run: docker compose -f docker-compose-tests.yml up --build -d
- name: Show Newman results
run: |
sleep 25s
docker logs trustvpn-tests
- name: Check Newman Exit Code
run: |
if [ $(docker inspect trustvpn-tests --format='{{.State.ExitCode}}') -ne 0 ]
then
echo "Newman failed."
exit 1
fi
- name: Stop the application
run: docker compose down
push:
runs-on: ubuntu-latest
if: ${{ contains(github.ref, 'refs/tags/v') }}
needs: test
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: maxirmx
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/maxirmx/trustvpn-backend
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: trustvpn-backend/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
test-ghrc:
runs-on: ubuntu-latest
if: ${{ contains(github.ref, 'refs/tags/v') }}
needs: push
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Start the application
run: docker compose -f docker-compose-ghrc-tests.yml up --build -d
- name: Show Newman results
run: |
sleep 25s
docker logs trustvpn-tests
- name: Check Newman Exit Code
run: |
if [ $(docker inspect trustvpn-tests --format='{{.State.ExitCode}}') -ne 0 ]
then
echo "Newman failed."
exit 1
fi
- name: Stop the application
run: docker compose down