Skip to content

store head sequence (#71) #19

store head sequence (#71)

store head sequence (#71) #19

Workflow file for this run

name: Build and deploy
on:
push:
branches: ['main']
release:
types: [published]
workflow_dispatch:
inputs:
branch:
description: 'Branch to use'
required: true
default: 'main'
network:
description: 'Network to deploy to'
required: true
default: 'testnet'
options:
- 'mainnet'
- 'testnet'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
setup:
runs-on: ubuntu-latest
outputs:
MAINNET: ${{ steps.set-vars.outputs.MAINNET }}
AWS_REGION: ${{ steps.set-vars.outputs.AWS_REGION }}
ENVIRONMENT_NAME: ${{ steps.set-vars.outputs.ENVIRONMENT_NAME }}
steps:
- name: Set variables
id: set-vars
run: |
MAINNET=$(if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.event.inputs.network }}" == "mainnet" ]] || [[ "${{ github.event_name }}" == "release" && "${{ github.event.action }}" == "published" ]]; then echo "true"; else echo "false"; fi)
AWS_REGION=$(if [[ "$MAINNET" == "true" ]]; then echo "us-east-1"; else echo "us-west-1"; fi)
ENVIRONMENT_NAME=$(if [[ "$MAINNET" == "true" ]]; then echo "wallet-server"; else echo "testnet-wallet-server"; fi)
echo "MAINNET=$MAINNET" >> $GITHUB_OUTPUT
echo "AWS_REGION=$AWS_REGION" >> $GITHUB_OUTPUT
echo "ENVIRONMENT_NAME=$ENVIRONMENT_NAME" >> $GITHUB_OUTPUT
echo "MAINNET=$MAINNET"
echo "AWS_REGION=$AWS_REGION"
echo "ENVIRONMENT_NAME=$ENVIRONMENT_NAME"
build-and-push-image:
needs: setup
runs-on: ubuntu-latest
env:
MAINNET: ${{ needs.setup.outputs.MAINNET }}
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ env.MAINNET == 'true' && 'mainnet' || 'testnet' }}
type=sha,value=${{ github.sha }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Deploy:
name: Redeploy server beanstalk environment
runs-on: ubuntu-latest
env:
MAINNET: ${{ needs.setup.outputs.MAINNET }}
AWS_REGION: ${{ needs.setup.outputs.AWS_REGION }}
ENVIRONMENT_NAME: ${{ needs.setup.outputs.ENVIRONMENT_NAME }}
needs: [build-and-push-image, setup]
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Fetch the active version label
run: echo "VERSION_LABEL=$(aws elasticbeanstalk describe-environments --query 'Environments[?EnvironmentName==`${{ env.ENVIRONMENT_NAME }}`&&Status!=`Terminated`].VersionLabel' --output text)" >> $GITHUB_ENV
- name: Redeploy the environment's active version
run: |
echo "Version label: ${{ env.VERSION_LABEL }}"
aws elasticbeanstalk update-environment --environment-name ${{ env.ENVIRONMENT_NAME }} --version-label ${{ env.VERSION_LABEL }}