Merge pull request #64 from chipp/mqtt #94
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: Publish and deploy | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
push: | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' | |
strategy: | |
matrix: | |
binary: [alisa, elisa, elizabeth] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Log into registry | |
run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@master | |
- name: Build and push image | |
run: | | |
IMAGE_ID=ghcr.io/chipp/${{ matrix.binary }} | |
docker buildx build . --file bin/${{ matrix.binary }}/Dockerfile \ | |
--push \ | |
--tag $IMAGE_ID:latest \ | |
--label "org.opencontainers.image.source=https://github.com/${{ github.repository }}" \ | |
--cache-from=type=registry,ref=$IMAGE_ID:cache \ | |
--cache-to=type=registry,ref=$IMAGE_ID:cache,mode=max | |
deploy: | |
runs-on: ubuntu-latest | |
needs: push | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Log into registry | |
run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin | |
- name: Add ssh key | |
run: | | |
mkdir ~/.ssh/ | |
echo "${{ secrets.ssh_key }}" > ~/.ssh/id_rsa | |
chmod -R 700 ~/.ssh/ | |
ssh-keyscan -H ${{ secrets.ssh_host }} > ~/.ssh/known_hosts | |
- name: Extract elisa | |
run: | | |
docker run --rm -v "$PWD/build:/build" ghcr.io/chipp/elisa:latest cp /root/elisa /build/elisa | |
- name: Copy artifacts | |
run: | | |
eval `ssh-agent -s` | |
echo "${{ secrets.ssh_key_passphrase }}" | ssh-add ~/.ssh/id_rsa | |
ssh ${{ secrets.ssh_user }}@${{ secrets.ssh_host }} \ | |
-i ~/.ssh/id_rsa \ | |
"echo test" | |
scp build/elisa conf/docker-compose.yml conf/mosquitto.conf \ | |
${{ secrets.ssh_user }}@${{ secrets.ssh_host }}:web/mq_lisa | |
- name: Deploy alisa and elizabeth | |
run: | | |
eval `ssh-agent -s` | |
echo "${{ secrets.ssh_key_passphrase }}" | ssh-add ~/.ssh/id_rsa | |
ssh ${{ secrets.ssh_user }}@${{ secrets.ssh_host }} \ | |
"cd ~/web/mq_lisa && docker-compose down --remove-orphans --rmi all && docker-compose up -d" | |
- name: Deploy elisa | |
run: | | |
eval `ssh-agent -s` | |
echo "${{ secrets.ssh_key_passphrase }}" | ssh-add ~/.ssh/id_rsa | |
ssh ${{ secrets.ssh_user }}@${{ secrets.ssh_host }} \ | |
"cd ~/web/mq_lisa && ssh pi 'sudo service elisa stop' && scp elisa pi:/usr/local/bin && ssh pi 'sudo service elisa start'" |