Skip to content

Instantly share code, notes, and snippets.

@dealloc
Last active October 7, 2020 18:45
Show Gist options
  • Save dealloc/cfe5c9b747976c38724b2721f22cf268 to your computer and use it in GitHub Desktop.
Save dealloc/cfe5c9b747976c38724b2721f22cf268 to your computer and use it in GitHub Desktop.
Elixir Docker makefile
version: '3'
services:
backend:
container_name: gcm_backend
build:
context: .
dockerfile: ./docker/Dockerfile
args:
- USER_UID=${USER_UID}
- UNAME=${UNAME}
user: ${USER_UID}
ports:
- "4000:4000"
command: mix phx.server
environment:
- MIX_ENV=dev
- PORT=4000
- DB_HOST=database
volumes:
- .:/app
links:
- database
database:
image: postgres
container_name: gcm_database
environment:
- POSTGRES_DB=password
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_HOST=database
FROM elixir:alpine
WORKDIR /app
ARG USER_UID
ARG UNAME
EXPOSE 4000
RUN apk add --no-cache curl bash
RUN curl --url https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh --output /wait-for-it.sh
COPY ./docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
RUN chmod +x /wait-for-it.sh
RUN apk del curl
# Add a user and group mimicing the current user on host system (this ensures correct permissions when developing on the host machine)
RUN adduser -D -u $USER_UID $UNAME
USER $UNAME
# Update hex
RUN mix local.hex --force
# Update rebar
RUN mix local.rebar --force
# Install Phoenix
RUN mix archive.install --force hex phx_new 1.4.0
ENTRYPOINT ["/entrypoint.sh"]
CMD ["mix", "phx.start"]
#!/usr/bin/env bash
if [[ -d "./deps" ]]; then
echo "Skipping 'mix deps.get' because dependencies already exist."
else
echo "Installing Mix dependencies because 'deps' folder does not exist."
mix deps.get deps.compile
fi
exec "$@";
.PHONY: all up shell down clean test
UID=$$(id -u)
UNAME=$$(whoami)
DOCKER_ENV=UNAME=$(UNAME) USER_UID=$(UID)
all: up
up:
$(DOCKER_ENV) docker-compose up backend
shell:
$(DOCKER_ENV) docker-compose run backend bash
down:
$(DOCKER_ENV) docker-compose down
clean:
$(DOCKER_ENV) docker-compose down --rmi all --remove-orphans
docker container prune --force
docker image prune --force
test:
$(DOCKER_ENV) docker-compose run backend tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment