Skip to content

Commit

Permalink
Merge pull request #49 from fablo-io/update-publish-docker-action
Browse files Browse the repository at this point in the history
Simplify publishing of docker image
  • Loading branch information
dzikowski authored Sep 16, 2024
2 parents 782d8ad + 4fe0c35 commit 148782e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 34 deletions.
37 changes: 5 additions & 32 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,10 @@ jobs:
- name: Check out repository code
uses: actions/checkout@v2

- name: Build fablo-rest
run: npm install && npm run lint && npm run build && ls -lh ./dist

- name: Read version
run: |
echo "DOCKER_IMAGE_VERSION=$(jq -r '.version' <"$GITHUB_WORKSPACE/package.json")" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
install: true

- name: Docker meta
id: meta
uses: docker/metadata-action@v3
uses: docker/setup-buildx-action@v3
with:
images: ${{ env.IMAGE_NAME }}
flavor: |
latest=true
prefix=
suffix=
tags: |
type=raw,value=${{ env.DOCKER_IMAGE_VERSION }}
driver: docker-container

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
Expand All @@ -48,14 +29,6 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push multi-arch image
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64 # Multi-arch platforms
push: true
tags: ${{ steps.meta.outputs.tags }}

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
- name: Build and push Docker image
run: |
./docker-build.sh --push
22 changes: 20 additions & 2 deletions docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,31 @@ FABLO_REST_VERSION=$(jq -r '.version' <"$FABLO_REST_HOME/package.json")
DOCKER_IMAGE_BASE_NAME="ghcr.io/fablo-io/fablo-rest"
DOCKER_IMAGE_TAG="$DOCKER_IMAGE_BASE_NAME:$FABLO_REST_VERSION"

COMMIT_HASH=$(git rev-parse --short HEAD)
BUILD_DATE=$(date +'%Y-%m-%d-%H:%M:%S')
VERSION_DETAILS="$BUILD_DATE-$COMMIT_HASH"

echo "Building new image..."
echo " FABLO_REST_HOME: $FABLO_REST_HOME"
echo " FABLO_REST_VERSION: $FABLO_REST_VERSION"
echo " DOCKER_IMAGE_TAG: [$DOCKER_IMAGE_BASE_NAME, $DOCKER_IMAGE_TAG]"
echo " VERSION_DETAILS: $VERSION_DETAILS"

npm install --silent
npm run build

docker build --tag "$DOCKER_IMAGE_TAG" "$FABLO_REST_HOME"
docker tag "$DOCKER_IMAGE_TAG" "$DOCKER_IMAGE_BASE_NAME"
# if --push is passed, then build for all platforms and push the image to the registry
if [ "${1:-''}" = "--push" ]; then
docker buildx build \
--build-arg VERSION_DETAILS="$VERSION_DETAILS" \
--platform linux/amd64,linux/arm64 \
--tag "$DOCKER_IMAGE_TAG" \
--push \
"$FABLO_REST_HOME"
else
docker build \
--build-arg VERSION_DETAILS="$VERSION_DETAILS" \
--tag "$DOCKER_IMAGE_TAG" \
"$FABLO_REST_HOME"
fi

0 comments on commit 148782e

Please sign in to comment.