Skip to content

Deploy Earth Observations API #14

Deploy Earth Observations API

Deploy Earth Observations API #14

Workflow file for this run

name: Deploy Earth Observations API
on:
workflow_dispatch:
inputs:
stack:
description: The stack to be deployed. stable (default - currently the only option)
required: true
default: stable
env:
SWARM_HOSTNAME: ${{ secrets.SWARM_HOSTNAME }} # Organization secret
SWARM_USERNAME: ${{ secrets.SWARM_USERNAME }} # Organization secret
SWARM_PASSWORD: ${{ secrets.SWARM_PASSWORD }} # Organization secret
SWARM_SSH_PORT: ${{ secrets.SWARM_SSH_PORT }} # Organization secret
BRANCH_REF: main
REGISTRY: ghcr.io
jobs:
build-raster:
runs-on: ubuntu-latest
outputs:
image: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout source code
uses: actions/checkout@main
with:
ref: ${{ env.BRANCH_REF }}
- name: Log in to the Container registry
uses: docker/login-action@master
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@master
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}_raster_${{ inputs.stack }}
tags: |
type=sha
- name: Build and push
uses: docker/build-push-action@master
with:
context: .
file: services/raster/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-stac:
runs-on: ubuntu-latest
outputs:
image: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout source code
uses: actions/checkout@main
with:
ref: ${{ env.BRANCH_REF }}
- name: Log in to the Container registry
uses: docker/login-action@master
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@master
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}_stac_${{ inputs.stack }}
tags: |
type=sha
- name: Build and push
uses: docker/build-push-action@master
with:
context: .
file: services/stac/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
deploy:
needs: [build-raster, build-stac]
runs-on: saeon
env:
STACK: ${{ inputs.stack }}
steps:
- uses: actions/checkout@main
with:
ref: ${{ env.BRANCH_REF }}
- name: (SCP) Copy Docker files to host
uses: appleboy/scp-action@master
with:
host: ${{ env.SWARM_HOSTNAME }}
username: ${{ env.SWARM_USERNAME }}
password: ${{ env.SWARM_PASSWORD }}
port: ${{ env.SWARM_SSH_PORT }}
source: deploy/${{ env.STACK }}/stack.yml
target: eoapi
- name: (SSH) Deploy Docker stack
uses: appleboy/ssh-action@master
with:
host: ${{ env.SWARM_HOSTNAME }}
username: ${{ env.SWARM_USERNAME }}
password: ${{ env.SWARM_PASSWORD }}
port: ${{ env.SWARM_SSH_PORT }}
script: |
echo "RASTER_IMAGE=${{ needs.build-raster.outputs.image }}" > /home/runner/eoapi/deploy/${{ env.STACK }}/stack.env
echo "STAC_IMAGE=${{ needs.build-stac.outputs.image }}" >> /home/runner/eoapi/deploy/${{ env.STACK }}/stack.env
echo "PG_USER=${{ secrets.PG_USER }}" >> /home/runner/eoapi/deploy/${{ env.STACK }}/stack.env
echo "PG_PASSWORD=${{ secrets.PG_PASSWORD }}" >> /home/runner/eoapi/deploy/${{ env.STACK }}/stack.env
echo "PG_HOST_STABLE=${{ secrets.PG_HOST_STABLE }}" >> /home/runner/eoapi/deploy/${{ env.STACK }}/stack.env
echo "PG_PORT_STABLE=${{ secrets.PG_PORT_STABLE }}" >> /home/runner/eoapi/deploy/${{ env.STACK }}/stack.env
sudo /opt/deploy-docker-stack.sh /home/runner/eoapi/deploy/${{ env.STACK }}/stack.yml /home/runner/eoapi/deploy/${{ env.STACK }}/stack.env eoapi_${{ env.STACK }}