Skip to content

Commit

Permalink
Update pishrink.sh v0.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
mgomesborges committed Jul 15, 2024
0 parents commit 326b7cd
Show file tree
Hide file tree
Showing 7 changed files with 685 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Set update schedule for GitHub Actions
version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
72 changes: 72 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Docker

on:
release:
types: [published]

env:
REGISTRY_GITHUB: ghcr.io
REGISTRY_DOCKER: docker.io
IMAGE_NAME_GITHUB: ${{ github.repository }}
IMAGE_NAME_DOCKER: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_APPNAME }}

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_GITHUB }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY_DOCKER }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_DOCKER }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
# Docker Hub Image
${{ env.REGISTRY_GITHUB }}/${{ env.IMAGE_NAME_GITHUB }}
# GitHub Image
${{ env.REGISTRY_DOCKER }}/${{ env.IMAGE_NAME_DOCKER }}
tags: |
type=semver,pattern={{raw}}
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=sha,enable=false
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
44 changes: 44 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
### macOS ###
*.DS_Store
.AppleDouble
.LSOverride

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk
47 changes: 47 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
FROM arm64v8/ubuntu:24.04

LABEL maintainer="Monsieur Borges"
LABEL version="1.0.0"
LABEL date="2024-07-15"

# ADD Installation Scripts
###########################################################
ADD ./scripts/pishrink.sh /usr/local/bin/pishrink

# Improve Terminal (make sure things are pretty)
###########################################################
ENV SHELL=/bin/bash
ENV LANG=C.UTF-8
ENV TERM=xterm-256color
ENV DEBIAN_FRONTEND=noninteractive

# Create a new Docker Image
###########################################################
WORKDIR /workdir

RUN apt-get update && \
# Install dependencies
#----------------------------------------------------------
apt-get --yes --quiet dist-upgrade\
&& apt-get install --yes --quiet --no-install-recommends \
wget \
parted \
gzip \
pigz \
xz-utils \
udev \
# Install dependencies
#----------------------------------------------------------
&& chmod +x /usr/local/bin/pishrink \
# Improve Terminal
#----------------------------------------------------------
&& cp /etc/skel/.bashrc ~/ \
&& sed -ri 's/^#force_color_prompt=yes/force_color_prompt=yes/' ~/.bashrc \
# Cleanup
#----------------------------------------------------------
&& rm -rf ~/.cache/* \
&& rm -rf /var/lib/apt/lists/*

# Build and Run
###########################################################
# docker build --rm --tag "monsieurborges/pishrink:latest" .
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MIT License

Copyright (c) Monsieur Borges.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# PiShrink dockerized

**PiShrink** automatically shrink a Raspberry Pi image in order to reduce the final image size.

It's great for saving disk space or sharing your Pi image on the Internet.

This project is a dockerized version of the [PiShrink bash script](https://github.com/Drewsif/PiShrink) by Drew Bonasera.

![Release][release-install-shield] ![Docker][docker-shield] [![License][license-shield]](LICENSE.md)

## Usage

1. Make a copy of a Raspberry Pi SD card that you want to shrink ([see instructions here](https://github.com/monsieurborges/raspberry-pi/blob/master/setup/clone-sd-card.md)).

2. Using the Terminal, access the directory containing the Raspberry Pi image:

```bash
cd ~/Directory-with-RPi-image
```

3. Run PiShrink dockerized:

```bash
docker run --privileged=true --rm \
--volume $(pwd):/workdir \
monsieurborges/pishrink \
pishrink -Zv IMAGE.img NEW-IMAGE.img
```

## PiShrink options

```shell
pishrink [-adhrsvzZ] IMAGE.img NEW-IMAGE.img
-s Do not expand filesystem when image is booted the first time
-v Enables more verbose output
-r Use advanced filesystem repair option if the normal one fails
-z Compress image after shrinking with gzip
-Z Compress image after shrinking with xz
-a Compress image in parallel using multiple cores
-d Write debug messages in a debug log file
```
If you specify the `NEW-IMAGE.img` parameter, the script will make a copy of `IMAGE.img` and work off that. You will need enough space to make a full copy of the image to use that option.
Check out [PiShrink GitHub](https://github.com/Drewsif/PiShrink) for more details.
## Docker Hub
* [monsieurborges/pishrink](https://hub.docker.com/r/monsieurborges/pishrink)
## Author
* [Monsieur Borges](https://github.com/monsieurborges)
## License
The source code is licensed under the [MIT license](LICENSE.md).
The content of this project itself is licensed under the [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0).
[release-install-shield]: https://img.shields.io/badge/Release-15--Jul--2024-blue
[license-shield]: https://img.shields.io/github/license/monsieurborges/pishrink-docker
[docker-shield]: https://github.com/monsieurborges/pishrink-docker/actions/workflows/docker-publish.yml/badge.svg
Loading

0 comments on commit 326b7cd

Please sign in to comment.