Automated CipherNode deployment #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/release' | |
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 |