Skip to content

Staging

Staging #120

Workflow file for this run

name: Staging
on:
workflow_dispatch:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
environment: Staging
steps:
- uses: actions/checkout@v4
- name: Login to Container Registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Get the latest tag
id: gettag
run: |
git fetch --tags
echo ::set-output name=TAG::$(git describe --tags $(git rev-list --tags --max-count=1))
- name: Create Deployment Files
shell: bash
env:
LOKI: ${{ secrets.LOKI_URL }}
CADDY: ${{ secrets.CADDY_FILE }}
AINV: ${{ secrets.ANSIBLE_INVENTORY }}
API_ENDPOINT: ${{ secrets.API_ENDPOINT }}
STAGING_API_ENDPOINT: ${{ secrets.STAGING_API_ENDPOINT }}
APKEY: ${{ secrets.ANSIBLE_PRIVATE_KEY }}
ENVARS: ${{ vars.ENVARS }}
run: |
echo "$AINV" > ./ansible/inventory.ini
echo "$APKEY" > ./ansible/key.pem
echo "$CADDY" > ./ansible/Caddyfile
echo "$ENVARS" > ./ansible/staging.env
echo "$ENVARS" > ./packages/api/.env
echo "$ENVARS" > ./packages/ui/.env
chmod 400 ./ansible/key.pem
sed -i "s#LOKI-REPLACE-ME#$LOKI#g" ./ansible/docker-compose.yml
sed -i "s#<LATEST_PROD>#${{ steps.gettag.outputs.TAG }}#g" ./ansible/docker-compose.yml
sed -i "s#<PRODUCTION_API_ENDPOINT>#$API_ENDPOINT#g" ./ansible/docker-compose.yml
sed -i "s#<STAGING_API_ENDPOINT>#$STAGING_API_ENDPOINT#g" ./ansible/docker-compose.yml
- name: Build Containers
env:
STAGING_API_ENDPOINT: ${{ secrets.STAGING_API_ENDPOINT }}
run: |
docker pull witnet/data-feed-app-ui:latest
docker pull witnet/data-feed-app-api:latest
docker build --build-arg API_ENDPOINT=${{ secrets.STAGING_API_ENDPOINT }} -t witnet/data-feed-app-ui:latest -f ./ansible/docker/ui.dockerfile ./packages/ui
docker build -t witnet/data-feed-app-api:latest -f ./ansible/docker/api.dockerfile ./packages/api
- name: Publish Containers
run: |
docker push witnet/data-feed-app-ui:latest
docker push witnet/data-feed-app-api:latest
- name: Deploy with Ansible
shell: bash
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
cd ansible
ansible-galaxy install -r requirements.yml
export ANSIBLE_CONFIG=./ansible.cfg
export ANSIBLE_FORCE_COLOR=True
export ANSIBLE_STDOUT_CALLBACK=yaml
export FORCE_COLOR=1
export TERM=xterm-color
ansible-playbook ./helper/docker-playbook.yml -vv
ansible-playbook playbook.yml -vv