Skip to content

Instantly share code, notes, and snippets.

@jimcavoli
Created November 11, 2020 00:56
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jimcavoli/b390565eb98f62faae821c83c8e87100 to your computer and use it in GitHub Desktop.
Save jimcavoli/b390565eb98f62faae821c83c8e87100 to your computer and use it in GitHub Desktop.
GitHub Actions workflows for custom Cloudron Apps
# Custom Cloudron App build/update workflow
#
# To use this template, ensure the following secrets
# * DOCKER_USERNAME
# * A Docker Hub account username
# * DOCKER_PASSWORD
# * The Docker Hub password for DOCKER_USERNAME
# * DOCKER_REPONAME
# * The repository belonging to DOCKER_USERNAME to push updates to
# * CLOUDRON_HOST
# * The Cloudron host to update (e.g. my.example.com)
# * CLOUDRON_TOKEN
# * A token for the Cloudron API on CLOUDRON_HOST with sufficient access
# * CLOUDRON_APPNAME
# * The name of the app as installed on the cloudron (e.g. myapp)
name: Release
# yamllint disable-line rule:truthy
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
env:
DOCKER_BUILDKIT: '1'
steps:
- uses: actions/checkout@v2
- id: cache-docker
name: Docker registry caching
uses: actions/cache@v2
with:
path: /tmp/docker-registry
key: docker-registry-buildkit-${{ hashFiles('Dockerfile') }}
- name: Start cache registry
run: docker run -d -p 5000:5000 --restart=always --name registry
-v /tmp/docker-registry:/var/lib/registry registry:2 && npx wait-on tcp:5000
- name: Warm local cache
run: docker pull localhost:5000/${{ secrets.DOCKER_REPONAME }} || true
- name: Image Build
run: docker build . -f Dockerfile.cloudron -t ${{ secrets.DOCKER_REPONAME }}
--build-arg BUILDKIT_INLINE_CACHE=1 --cache-from=localhost:5000/${{ secrets.DOCKER_REPONAME }}
- name: Update cache registry
run: docker tag ${{ secrets.DOCKER_REPONAME }} localhost:5000/${{ secrets.DOCKER_REPONAME }}:latest &&
docker push localhost:5000/${{ secrets.DOCKER_REPONAME }} || true
if: steps.cache-docker.outputs.cache-hit != 'true'
- name: Log into docker.io registry
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Tag and push final image
run: |
IMAGE_ID=${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPONAME }}
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag ${{ secrets.DOCKER_REPONAME }} $IMAGE_ID:$VERSION
docker tag ${{ secrets.DOCKER_REPONAME }} $IMAGE_ID:latest
docker push $IMAGE_ID:$VERSION
docker push $IMAGE_ID:latest
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v2
- name: Environment Setup
uses: actions/setup-node@v2-beta
with:
node-version: '14'
- name: Deploy setup
run: npm install -g cloudron
- name: Update App
run: |
update="cloudron update --no-wait \
--server ${{ secrets.CLOUDRON_HOST }} \
--token ${{ secrets.CLOUDRON_TOKEN }} \
--app ${{ secrets.CLOUDRON_APPNAME }} \
--image docker.io/${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPONAME }}:latest"
# Retry up to 5 times (with linear backoff)
NEXT_WAIT_TIME=0
until [ $NEXT_WAIT_TIME -eq 5 ] || $update; do
sleep $(( NEXT_WAIT_TIME++ ))
done
[ $NEXT_WAIT_TIME -lt 5 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment