-
Notifications
You must be signed in to change notification settings - Fork 1
105 lines (96 loc) · 3.71 KB
/
build-deploy.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: Build and deploy
on:
push:
branches: ['main']
release:
types: [published]
workflow_dispatch:
inputs:
branch:
description: 'Branch to use'
required: true
default: 'main'
network:
type: choice
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@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
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@v6
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@v4
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 }}