Skip to content

Commit

Permalink
build(docker): Move env variables as runtime env variables (#262)
Browse files Browse the repository at this point in the history
- Use boolean for `INSIDE_DOCKER`
- Add documentation about environments variables
- Use `==` instead of `=`
  • Loading branch information
aifrak authored Jan 24, 2022
1 parent 3721392 commit 4a48ab3
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 16 deletions.
14 changes: 2 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ FROM ubuntu:focal-20220105 as base

USER root

ENV INSIDE_DOCKER=1
ENV LANG=en_US.UTF-8

# Required packages:
# - for erlang: libodbc1, libssl1, libsctp1
RUN set -e \
Expand All @@ -22,16 +19,13 @@ RUN set -e \
libsctp1=1.0.18+* \
locales=2.31-* \
&& echo "--- Add locales ---" \
&& sed -i "/${LANG}/s/^# //g" /etc/locale.gen \
&& locale-gen ${LANG} \
&& sed -i "/en_US.UTF-8/s/^# //g" /etc/locale.gen \
&& locale-gen "en_US.UTF-8" \
&& echo "--- Clean ---" \
&& apt-get clean \
&& apt-get autoremove \
&& rm -rf /var/lib/apt/lists/*

# Added here instead before `locale-gen` to avoid warnings
ENV LC_ALL=${LANG}

ENV USERNAME=app-user
ARG GROUPNAME=${USERNAME}
ARG USER_UID=1000
Expand Down Expand Up @@ -103,8 +97,6 @@ COPY --from=elixir --chown=${USERNAME} /root/.mix ${HOME}/.mix

USER ${USERNAME}

ENV CI=true

# —————————————————————————————————————————————— #
# dev #
# —————————————————————————————————————————————— #
Expand All @@ -130,8 +122,6 @@ RUN set -e \
&& apt-get autoremove \
&& rm -rf /var/lib/apt/lists/*

ENV CI=false

USER ${USERNAME}

# —————————————————————————————————————————————— #
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ services:
image: aifrak/template-elixir:ci
build:
target: ci
environment:
- CI=true
2 changes: 2 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ services:
image: aifrak/template-elixir:dev
build:
target: dev
environment:
- CI=false
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ services:
USER_GID: ${USER_GID:-1000}
user: ${USER_UID:-1000}:${USER_GID:-1000}
command: sleep infinity
environment:
- INSIDE_DOCKER=true
- LANG=en_US.UTF-8
volumes:
- .:/app
43 changes: 43 additions & 0 deletions docs/docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Docker

## `app` service

### Environment variables

<!-- markdownlint-disable no-inline-html-->

<table>
<tr>
<th>Name</th>
<th>Description</th>
<th align="center">Custom</th>
<th>Possible value(s)</th>
</tr>
<tr>
<td><code>CI</code></td>
<td>Check if <code>./run</code> is executed on a CI environment.</td>
<td align="center">✅</td>
<td><code>true</code> or <code>false</code></td>
</tr>
<tr>
<td><code>INSIDE_DOCKER</code></td>
<td>Check if <code>./run</code> is executed in a docker container.</td>
<td align="center">✅</td>
<td><code>true</code> or <code>false</code></td>
</tr>
<tr>
<td><code>LANG</code></td>
<td>System variable for locales.</td>
<td align="center">❌</td>
<td>
<ul>
<li><code>en_US.UTF-8</code> (recommended)</li>
<li><code>C</code></li>
<li><code>C.UTF-8</code></li>
<li><code>POSIX</code></li>
</ul>
</td>
</tr>
</table>

<!-- markdownlint-enable -->
5 changes: 2 additions & 3 deletions run
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,16 @@ EOF
# —————————————————————————————————————————————— #

# Check if the command is from the docker container or the host.
# INSIDE_DOCKER=1 is set from the Dockerfile
function is_inside_docker {
if [[ ${INSIDE_DOCKER:-0} -eq 1 ]]; then
if [[ ${INSIDE_DOCKER:-false} == true ]]; then
return 0
else
return 1
fi
}

function is_ci {
if [[ "${CI:-false}" = true ]]; then
if [[ "${CI:-false}" == true ]]; then
return 0
else
return 1
Expand Down
2 changes: 1 addition & 1 deletion spellcheck/dictionaries/workspace.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Ascending sort, case insensitive
!hte
calver
codecov
Expand All @@ -9,6 +8,7 @@ dockerfiles
GROUPNAME
infile
noreply
POSIX
prealpha
preminor
prepatch
Expand Down

0 comments on commit 4a48ab3

Please sign in to comment.