-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds github workflow for dev deployments
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
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
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
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 |