Skip to content

Commit

Permalink
Merge pull request #22 from thalesmg/docker-release
Browse files Browse the repository at this point in the history
ci: add docker image to release
  • Loading branch information
thalesmg authored Nov 7, 2024
2 parents 9aad454 + eab7258 commit 63fd470
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 9 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,51 @@ jobs:
files: packages/*
draft: ${{ github.ref_type != 'tag' }}
prerelease: ${{ github.ref_type != 'tag' }}

docker:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os:
- ubuntu24.04
needs:
- init
steps:
- name: Checkout
uses: actions/[email protected]
with:
ref: ${{ github.event.inputs.ref }}
- name: Compute RUN_FROM
id: run_from
run: |
RUN_FROM=$(./scripts/compute-run-from.sh ${{ matrix.os }})
echo "RUN_FROM=$RUN_FROM" | tee -a "$GITHUB_OUTPUT"
- name: Docker Metadata action
uses: docker/[email protected]
id: meta
with:
images: |
ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
- uses: docker/setup-buildx-action@v2
- uses: docker/setup-qemu-action@v2
- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Build and push Docker images
uses: docker/[email protected]
with:
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BUILD_FROM=ghcr.io/emqx/emqx-builder/${{ needs.init.outputs.BUILDER_VSN }}:${{ needs.init.outputs.ELIXIR_VSN }}-${{ needs.init.outputs.OTP_VSN }}-${{ matrix.os }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ rebar.lock
Mnesia*
TAGS
emqx-export*.tar.gz
/dist/
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ARG BUILD_FROM
ARG RUN_FROM=ubuntu:24.04

FROM ${BUILD_FROM} AS builder

Check warning on line 4 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker (ubuntu24.04)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG ${BUILD_FROM} results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

COPY . /build

WORKDIR /build

RUN /build/build

FROM ${RUN_FROM} AS runner

WORKDIR /opt/converter

COPY --from=builder /build/dist/. /opt/converter/.

ENTRYPOINT ["/opt/converter/bin/emqx_data_converter"]
16 changes: 16 additions & 0 deletions build
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -euo pipefail

rebar3 escriptize

DIST_DIR="${DIST_DIR:-dist}"

ERL_ROOT=$(erl -noinput -eval 'io:format("~s",[code:root_dir()]),halt().')
ERL_DIR=$(basename $ERL_ROOT)
rm -rf "$DIST_DIR"
cp -R ${ERL_ROOT%/} _build/
mv _build/default/bin/emqx_data_converter _build/$ERL_DIR/bin/emqx_data_converter.escript
cp -f _build/$ERL_DIR/bin/escript _build/$ERL_DIR/bin/emqx_data_converter
mkdir "$DIST_DIR"
mv _build/$ERL_DIR/* "$DIST_DIR/."
14 changes: 5 additions & 9 deletions package
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

set -euo pipefail

rebar3 escriptize

export DIST_DIR="dist"
ERL_ROOT=$(erl -noinput -eval 'io:format("~s",[code:root_dir()]),halt().')
ERL_DIR=$(basename $ERL_ROOT)
rm -rf _build/emqx_data_converter
cp -R ${ERL_ROOT%/} _build/
mv _build/default/bin/emqx_data_converter _build/$ERL_DIR/bin/emqx_data_converter.escript
cp -f _build/$ERL_DIR/bin/escript _build/$ERL_DIR/bin/emqx_data_converter
mkdir _build/emqx_data_converter
mv _build/$ERL_DIR/* _build/emqx_data_converter
tar -czf _build/emqx_data_converter.tar.gz -C _build emqx_data_converter

./build

tar -czf _build/emqx_data_converter.tar.gz -C "$DIST_DIR" .
rm -rf _build/emqx_data_converter
rm -rf _build/$ERL_DIR

Expand Down
14 changes: 14 additions & 0 deletions scripts/compute-run-from.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -euo pipefail

case "$1" in
ubuntu*)
VSN=${1#ubuntu}
echo "ubuntu:$VSN"
;;
*)
echo "unsupported OS: $1"
exit 1
;;
esac

0 comments on commit 63fd470

Please sign in to comment.