Release 0.5.1 #15
Workflow file for this run
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: Deploy Latest Release | |
on: | |
workflow_dispatch: | |
release: | |
types: | |
- created | |
jobs: | |
build_and_push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Install jq on GitHub Actions runner | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y jq | |
- name: Build Docker image | |
run: | | |
latest_version=$(curl -sL https://api.github.com/repos/dataswap/explorer/releases | jq -r ".[0].tag_name") | |
mv ./.env.example.json ./.env.json | |
sed -i 's/"messageHubUrl": "http:\/\/localhost:3000"/"messageHubUrl": "http:\/\/${{ secrets.MESSAGEHUB_SERVER }}"/' ./.env.json | |
sudo docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/explorer:${latest_version} . | |
sudo docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} | |
sudo docker push ${{ secrets.DOCKERHUB_USERNAME }}/explorer:${latest_version} | |
- name: SSH into deployment server AND Deploy explorer | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SERVER_HOST }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
password: ${{ secrets.SERVER_PRIVATE_KEY }} | |
port: ${{ secrets.SERVER_PORT }} | |
script: | | |
sudo apt-get update | |
sudo apt-get install -y jq | |
latest_version=$(curl -sL https://api.github.com/repos/dataswap/explorer/releases | jq -r ".[0].tag_name") | |
echo ${latest_version} | |
container_id=$(sudo docker ps -a | grep "${{ vars.PORT}}" | awk -F " " '{print $1}') | |
if [ -n "$container_id" ]; then | |
sudo docker stop "$container_id" | |
sudo docker rm "$container_id" | |
fi | |
sudo docker stop explorer | |
sudo docker rm explorer | |
sudo docker pull "${{ secrets.DOCKERHUB_USERNAME }}/explorer:${latest_version}" | |
sudo docker run -d -p ${{ vars.EXTERNAL_PORT}}:${{ vars.PORT}} --name explorer "${{ secrets.DOCKERHUB_USERNAME }}/explorer:${latest_version}" | |
sleep 10 | |
container_status=$(sudo docker inspect -f '{{.State.Status}}' explorer) | |
if [ "$container_status" = "running" ]; then | |
echo "explorer container started successfully." | |
else | |
echo "Error: explorer container failed to start (status: $container_status)." | |
exit 1 | |
fi | |
sudo docker ps -a |grep explorer |