Skip to content

Commit

Permalink
improvement: upgrade elixir to 1.17.2 and add docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
cao7113 committed Jul 12, 2024
1 parent c61c6ca commit e2a47bf
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
elixir 1.17.1-otp-27
elixir 1.17.2-otp-27
erlang 27.0
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20240612-slim - for the release image
# - https://pkgs.org/ - resource for finding needed packages
# - Ex: hexpm/elixir:1.17.1-erlang-27.0-debian-bullseye-20240612-slim
#
ARG ELIXIR_VERSION=1.17.1
ARG OTP_VERSION=27.0
ARG DEBIAN_VERSION=bullseye-20240612-slim
# - Ex: hexpm/elixir:1.17.2-erlang-27.0-debian-bullseye-20240701-slim
#
# hexpm/elixir images built by https://github.com/hexpm/bob#docker-images

ARG ELIXIR_VERSION=1.17.2
ARG OTP_VERSION=27.0
ARG DEBIAN_VERSION=bullseye-20240701-slim
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"

Expand Down
15 changes: 12 additions & 3 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ tasks:
orb-setup-local: cp run/deploy.sh _build/orb-prod/

## Docker env
dk-pull-builder: docker pull hexpm/elixir:1.17.1-erlang-27.0-debian-bullseye-20240612-slim
dk-pull-runner: docker pull debian:bullseye-20240612-slim
# dockerhub images
# https://hub.docker.com/r/cao7113/hello-api-elixir
# https://github.com/cao7113/hello-api-elixir/pkgs/container/hello-api-elixir
dk-pull-ghcr: docker pull ghcr.io/cao7113/hello-api-elixir
Expand All @@ -59,5 +56,17 @@ tasks:
dk-sh: docker run --rm -it ghcr.io/cao7113/hello-api-elixir sh
# cat /etc/os-release or cat /etc/debian_version

## Get images
dk-pull-builder: docker pull hexpm/elixir:1.17.2-erlang-27.0-debian-bullseye-20240701-slim
dk-pull-runner: docker pull debian:bullseye-20240701-slim
# https://github.com/OpenLinkOS/registry-mirrors
get-images: |
docker pull docker.linkos.org/hexpm/elixir:1.17.2-erlang-27.0-debian-bullseye-20240701-slim
docker tag docker.linkos.org/hexpm/elixir:1.17.2-erlang-27.0-debian-bullseye-20240701-slim hexpm/elixir:1.17.2-erlang-27.0-debian-bullseye-20240701-slim
# docker rmi docker.linkos.org/hexpm/elixir:1.17.2-erlang-27.0-debian-bullseye-20240701-slim
docker pull docker.linkos.org/library/debian:bullseye-20240701-slim
docker tag docker.linkos.org/library/debian:bullseye-20240701-slim debian:bullseye-20240701-slim
# Init setup
mk-hello: mix new hello-api-elixir --app hello_api --sup
52 changes: 52 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# https://docs.docker.com/compose/compose-file/05-services/
services:
# https://github.com/cao7113/hello-phx/pkgs/container/hello-api-elixir
api:
# image: ghcr.io/cao7113/hello-api-elixir
build: .
# environment:
# MIX_ENV: "prod"
# https://docs.docker.com/compose/compose-file/05-services/#healthcheck
healthcheck:
test: bin/hello_api pid || exit 1
interval: 1m30s
timeout: 10s
retries: 3
start_period: 40s
start_interval: 5s

# http://hello-api-elixir-api-1.orb.local/

curl:
image: curlimages/curl:8.8.0
depends_on:
- api
command: >
sh -c "
sleep 2
echo ping api
curl http://api/ping
echo
echo ping api at port 4000
curl http://api:4000/ping
echo
ping -c 3 api
ping -q api
"
tool:
image: busybox
depends_on:
- api
command: >
sh -c "
sleep 2
echo ping api
wget -qO- http://api/ping
echo
echo ping api at port 4000
wget -qO- http://api:4000/ping
echo
ping -c 3 api
ping -q api
"
7 changes: 6 additions & 1 deletion lib/hello_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,10 @@ defmodule HelloApi do
def parse_commit_time(""), do: nil

def parse_commit_time(tm_str),
do: tm_str |> String.trim() |> String.to_integer() |> DateTime.from_unix!() |> to_string()
do:
tm_str
|> String.trim()
|> String.to_integer()
|> DateTime.from_unix!()
|> to_string()
end

0 comments on commit e2a47bf

Please sign in to comment.