generated from PaulRBerg/hardhat-template
-
Notifications
You must be signed in to change notification settings - Fork 4
77 lines (64 loc) · 1.9 KB
/
ec2-deployment.yml
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
name: Build and Deploy Ciphernode
on:
push:
branches:
- main
paths:
- 'packages/ciphernode/**'
- 'packages/evm/contracts/**'
pull_request:
branches:
- main
paths:
- 'packages/ciphernode/**'
- 'packages/evm/contracts/**'
env:
DOCKERFILE_PATH: packages/ciphernode/Dockerfile
IMAGE_NAME: ghcr.io/gnosisguild/ciphernode
permissions:
contents: read
packages: write
jobs:
deploy:
name: Deploy to GHCR
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build, tag, and push image to GHCR
id: build-image
env:
IMAGE_TAG: ${{ github.sha }}
run: |
# Build the image
docker build -t $IMAGE_NAME:$IMAGE_TAG -t $IMAGE_NAME:latest -f $DOCKERFILE_PATH .
# Push both tagged and latest images
docker push $IMAGE_NAME:$IMAGE_TAG
docker push $IMAGE_NAME:latest
# Output image details
echo "image=$IMAGE_NAME:$IMAGE_TAG" >> $GITHUB_OUTPUT
echo "image=$IMAGE_NAME:latest" >> $GITHUB_OUTPUT
- name: Deploy to EC2
uses: appleboy/[email protected]
if: github.ref == 'refs/heads/main'
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_KEY }}
script: |
# Pull the latest image
echo "Pulling latest image $IMAGE_NAME:latest"
docker pull $IMAGE_NAME:latest
# Cd into the directory
cd /home/ec2-user/enclave
# Pull the latest changes
git pull
# Deploy the stack
docker stack deploy -c docker-compose.yml ciphernode-stack