Build Docker #120
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Docker | |
on: | |
page_build: | |
workflow_dispatch: | |
inputs: | |
comment: | |
description: 'Comment' | |
required: false | |
default: '' | |
env: | |
REPO: nugu-linux | |
REPOSLUG: nugu-developers/nugu-linux | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v4 | |
- name: Generate docker image | |
run: | | |
echo "OS=$OSTYPE" | |
function docker_check() { | |
docker pull nugulinux/sdk:unstable | |
} | |
if docker_check; then | |
echo "Download success" | |
else | |
echo "Image not exist" | |
echo "commit=x" >> $GITHUB_ENV | |
exit | |
fi | |
URL_PACKAGES=https://raw.githubusercontent.com/nugulinux/sdk-unstable/gh-pages/ubuntu/dists/focal/main/binary-amd64/Packages | |
PKG_VERSION=$(curl -s -X GET $URL_PACKAGES | grep Version | head -1) | |
PKG_SHA=$(echo $PKG_VERSION | sed 's/.*\(.......\)~.*/\1/') | |
echo "Commit from Github pages: $PKG_SHA" | |
LAST_COMMIT=`docker run -t --rm nugulinux/sdk:unstable printenv | grep LAST_COMMIT` | |
echo $LAST_COMMIT | |
COMMIT= | |
if [[ "$OSTYPE" == "linux-gnu"* ]]; then | |
COMMIT=$(echo $LAST_COMMIT | sed -r 's/LAST_COMMIT=(.*)/\1/' | tr -d '\r') | |
elif [[ "$OSTYPE" == "darwin"* ]]; then | |
COMMIT=$(echo $LAST_COMMIT | gsed -r 's/LAST_COMMIT=(.*)/\1/' | tr -d '\r') | |
fi | |
echo "nugulinux/sdk:unstable docker commit='${COMMIT}'" | |
if [[ "${COMMIT}" == "${PKG_SHA}" ]]; then | |
echo "Same version" | |
NEED_BUILD=0 | |
else | |
echo "not match" | |
NEED_BUILD=1 | |
fi | |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
echo "force build" | |
NEED_BUILD=1 | |
fi | |
echo "commit=${COMMIT}" >> $GITHUB_ENV | |
echo "sha=${PKG_SHA}" >> $GITHUB_ENV | |
echo "build=${NEED_BUILD}" >> $GITHUB_ENV | |
- name: Information | |
run: | | |
echo "${{ env.sha }}" | |
echo "${{ env.commit }}" | |
echo "${{ env.build }}" | |
- name: Set up QEMU | |
if: ${{ env.build == 1}} | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
if: ${{ env.build == 1}} | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
if: ${{ env.build == 1}} | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push | |
if: ${{ env.build == 1}} | |
uses: docker/build-push-action@v5 | |
with: | |
context: docker/. | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: nugulinux/sdk:unstable | |
build-args: | | |
LAST_COMMIT=${{ env.sha }} |