Skip to content

Instantly share code, notes, and snippets.

@peeush-agarwal
Last active February 28, 2022 02:58
Show Gist options
  • Save peeush-agarwal/cdd83f35c287c6340b714afa73983268 to your computer and use it in GitHub Desktop.
Save peeush-agarwal/cdd83f35c287c6340b714afa73983268 to your computer and use it in GitHub Desktop.
GitHub workflow file changes with docker container
# This is a basic workflow to help you get started with Actions
name: Deploy to Raspberry Pi
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: self-hosted
outputs:
tag_name: ${{ steps.set_tag_name.outputs.tag_name }}
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout repository
uses: actions/checkout@v2
- name: Set TAG_NAME
id: set_tag_name
run: echo "::set-output name=tag_name::$(date +%s)"
- name: Create a docker image
run: |
cd src/
docker build -t rpi-cd-tutorial:${{ steps.set_tag_name.outputs.tag_name }} .
deploy:
runs-on: self-hosted
needs: build
steps:
- name: Kill all running containers
run: docker kill $(docker ps -q)
- name: Run the docker image
run: docker run -d -p4000:4000 rpi-cd-tutorial:${{ needs.build.outputs.tag_name }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment