Merge pull request #299 from cardanoapi/fix/status-page-endpoints #202
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: Docker Build and Deploy | |
on: | |
push: | |
branches: | |
- master | |
- dev | |
tags: | |
- "*" | |
jobs: | |
build_on_push: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
service: | |
- agent-manager | |
- api | |
- agent-node | |
- frontend | |
- dbsync-api | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ vars.DOCKER_REGISTRY_HOST }} | |
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }} | |
password: ${{ secrets.DOCKER_REGISTRY_SECRET }} | |
- name: Build and push Docker image | |
id: docker_build | |
env: | |
SERVICE_NAME: ${{ matrix.service }} | |
run: | | |
REPO_NAME="${GITHUB_REPOSITORY##*/}" | |
COMMON_TAG="${{ vars.DEV_IMAGE_TAG }}" | |
if [[ "${{ github.ref }}" == "refs/heads/master" ]]; then | |
COMMON_TAG="latest" | |
fi | |
# conditionally set the image name to repo name in case of agent. | |
if [[ "${SERVICE_NAME}" == "agent-node" ]]; then | |
IMAGE_NAME="${{ vars.DOCKER_REGISTRY_HOST }}/${{ vars.DOCKER_IMAGE_PREFIX }}/${REPO_NAME}" | |
else | |
IMAGE_NAME="${{ vars.DOCKER_REGISTRY_HOST }}/${{ vars.DOCKER_IMAGE_PREFIX }}/${REPO_NAME}-${SERVICE_NAME}" | |
fi | |
# frontend build fails with some network error when built with buidx in github runner. | |
if [[ "${SERVICE_NAME}" == "frontend" ]]; then | |
docker build -t "$IMAGE_NAME:${{ github.sha }}" -t "$IMAGE_NAME:$COMMON_TAG" ${SERVICE_NAME} | |
docker push "$IMAGE_NAME:${{ github.sha }}" | |
docker push "$IMAGE_NAME:$COMMON_TAG" | |
else | |
# use buildx | |
docker buildx build \ | |
--platform linux/amd64,linux/arm64 \ | |
-t "$IMAGE_NAME:${{ github.sha }}" \ | |
-t "$IMAGE_NAME:$COMMON_TAG" \ | |
${SERVICE_NAME} \ | |
--push | |
fi | |
deploy_services: | |
needs: build_on_push | |
strategy: | |
matrix: | |
service: | |
- agent-manager | |
- api | |
- frontend | |
- dbsync-api | |
max-parallel: 1 | |
runs-on: ubuntu-latest | |
env: | |
SERVICE_NAME: ${{ matrix.service }} | |
GITHUB_REPOSITORY: ${{ github.repository }} | |
steps: | |
- name: Deploy built Image | |
id: docker_deploy | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.BASTION_IPV4 }} | |
username: ${{ secrets.BASTION_SSH_USER }} | |
key: ${{ secrets.BASTION_SSH_KEY }} | |
port: ${{ secrets.BASTION_SSH_PORT }} | |
script: | | |
SERVICE_NAME=$(echo ${{ matrix.service }}) | |
GITHUB_REPOSITORY="${{ github.repository }}" | |
REPO_NAME="${GITHUB_REPOSITORY##*/}" | |
IMAGE_NAME="${{ vars.DOCKER_REGISTRY_HOST }}/${{ vars.DOCKER_IMAGE_PREFIX }}/${REPO_NAME}-${SERVICE_NAME}" | |
DEPLOY_TAG="${{ github.sha }}" | |
if [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then | |
DOCKER_HOST="${{ vars.DEV_HOST }}" | |
DOCKER_STACK="${{ vars.DEV_STACK }}" | |
elif [[ "${{ github.ref }}" == "refs/heads/master" ]]; then | |
DOCKER_HOST="${{ vars.PROD_HOST }}" | |
DOCKER_STACK="${{ vars.PROD_STACK }}" | |
fi | |
echo docker --host "$DOCKER_HOST" service update --image $IMAGE_NAME:$DEPLOY_TAG ${DOCKER_STACK}_${SERVICE_NAME} | |
docker --host "$DOCKER_HOST" service update --image $IMAGE_NAME:$DEPLOY_TAG ${DOCKER_STACK}_${SERVICE_NAME} |