Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite GH actions #38

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/build+push_docker_image .yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build+Push docker images

on:
push:
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 --push \
--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 }}
73 changes: 3 additions & 70 deletions .github/workflows/build_docker_image.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
name: Build docker images

on:
push:
pull_request:
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 }}
Loading