Skip to content

Commit

Permalink
rewrite GH actions
Browse files Browse the repository at this point in the history
  • Loading branch information
NL-TCH committed May 3, 2024
1 parent 8e9f65a commit a1fc5cb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 69 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/build+push_docker_image .yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build docker images

on:
push:
branches: [ 'master' ]
pull_request:
branches: [ 'master' ]
schedule:
- cron: "0 0 * * 0"

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout code from Git repository
uses: actions/checkout@v2

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

- name: Docker login to GitHub
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push the image
run: |
docker buildx build --platform=linux/arm64,linux/amd64,linux/arm64,linux/arm/v7 . --tag ghcr.io/RaspAP/raspap-docker:latest --tag ghcr.io/RaspAP/raspap-docker:${{ github.run_number }}
docker push ghcr.io/RaspAP/raspap-docker --all-tags
71 changes: 2 additions & 69 deletions .github/workflows/build_docker_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ name: Build docker images
on:
push:
branches: [ 'master' ]
schedule:
# Cron execution is for weekly dependencies update (for security update)
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
- cron: "0 0 * * 0"

jobs:
build:
Expand All @@ -20,76 +12,17 @@ jobs:
- name: Checkout code from Git repository
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

# Only if you want the image to be push to docker.io instead of the GitHub Package repository
# - name: Docker login to DockerHub
# uses: docker/login-action@v1
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}

# Comment this if you prefer to use the docker.io image repository | This method can be better because it didn't need any password (use the credentials of the people who commit)
- name: Docker login to GitHub
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Prepare available platforms build
env: # Here you need to test on what platform your docker image can be build. Important one is linux/arm/v7, linux/arm64 and linux/amd64
requested_platforms: "linux/amd64,linux/arm64,linux/arm/v7" # jrei/systemd-debian:10 support only i386, amd64, arm and arm64
image: "ghcr.io/${{ github.repository }}:latest"
run: |
# If you use the `requested_platforms` env var, then parse it.
if [ -n "${requested_platforms}" ]; then
# Transform env var into bash array to calculate arrays intersect. That allow us to know the plateform that can work with our image who can be build on current github docker buildx.
IFS=',' read -r -a requested_platforms <<< "${requested_platforms}"
IFS=',' read -r -a available_platforms <<< "${{ steps.buildx.outputs.platforms }}"
# Only got the intersect of two arrays
available_platforms=$(comm -12 <(printf '%s\n' "${requested_platforms[@]}" | LC_ALL=C sort) <(printf '%s\n' "${available_platforms[@]}" | LC_ALL=C sort))
# Just format the output for the docker commands
requested_platforms="${requested_platforms//'
'/,}"
available_platforms="${available_platforms//'
'/,}"
else
available_platforms="${{ steps.buildx.outputs.platforms }}"
fi
echo "available_platforms=$available_platforms"
# Save Available platforms
echo "available_platforms=${available_platforms}" >> $GITHUB_ENV
echo "docker_image=${image,,}" >> $GITHUB_ENV
# Use cache image for quicker build time.
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
# Use official buildx GitHub Action
- name: Docker build & push
uses: docker/build-push-action@v2
with:
context: .
push: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
platforms: ${{ env.available_platforms }}
tags: ${{ env.docker_image }}

# Save new cache
- name: Move cache
- name: Build the image
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
docker buildx build --platform=linux/arm64,linux/amd64,linux/arm64,linux/arm/v7 . --tag ghcr.io/RaspAP/raspap-docker:latest --tag ghcr.io/RaspAP/raspap-docker:${{ github.run_number }}

0 comments on commit a1fc5cb

Please sign in to comment.