Skip to content

Commit

Permalink
Adds github workflow for dev deployments
Browse files Browse the repository at this point in the history
It builds the image using buildx, uploads it to GHCR.io, sets up rPI
credentials, pulls the image from GHCR.io and finally runs it with
docker-compose.
  • Loading branch information
MinusFour committed Sep 23, 2020
1 parent a95a8d9 commit ad36371
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: deployment
on:
push:
branch: dev
jobs:
build_dev_pi_image:
name: Build docker image for rPIv2 (Arm v6)
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
-
name: Login to GHCR
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.CR_USER }}
password: ${{ secrets.CR_PAT }}
-
name: Create builder
uses: docker/setup-buildx-action@v1

-
name: Build and push docker image
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/armv6-node/Dockerfile
platforms: linux/arm/v6
push: true
tags:
ghcr.io/elhacker-net/web-nuevo/arm32v6/web-dev:latest
deploy_to_rpi:
name: Pull image from GHCR and run with docker-compose
needs: build_dev_pi_image
runs-on: ubuntu-18.04
env:
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_PORT: ${{ secrets.SSH_PORT }}
steps:
- uses: actions/checkout@v2
-
name: Set DOCKER_HOST
run: echo "::set-env name=DOCKER_HOST::ssh://$SSH_USER@$SSH_HOST:$SSH_PORT"
-
name: Set SSH client
env:
SSH_PRIVATE_KEY: ${{ secrets.GA_PRIV_KEY }}
HOST_KEY: ${{ secrets.HOST_KEY }}
SSH_HOST: ${{ secrets.SSH_HOST }}
run: |
mkdir -p $HOME/.ssh
echo "$SSH_PRIVATE_KEY" > $HOME/.ssh/id_rsa
chmod 600 $HOME/.ssh/id_rsa
eval $(ssh-agent)
ssh-add $HOME/.ssh/id_rsa
echo "$SSH_HOST $HOST_KEY" > /etc/ssh/ssh_known_hosts
echo ::set-env name=SSH_AUTH_SOCK::$SSH_AUTH_SOCK
echo ::set-env name=SSH_AGENT_PID::$SSH_AGENT_PID
-
name: Login to GHCR
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.CR_USER }}
password: ${{ secrets.CR_PAT }}
-
name: Pull image and run in host
run: |
docker-compose pull
docker-compose up -d

0 comments on commit ad36371

Please sign in to comment.