Fix permissions when running dev container as non-root user

I wanted to pass `—user` to `docker-compose` up, but that option doesnt exist. To get around this, I had to record the uid on the host (CURRENT_UID), interpolate the variable in tools/docker-compose.yml, and detect that inside the container. I then piggy-backed on the /etc/passwd hack we use for scenarios with unpredictable uids.
This commit is contained in:
Shane McDonald
2018-10-22 19:02:31 -04:00
committed by Ryan Petrello
parent 7df63830ed
commit a361b5da6e
7 changed files with 23 additions and 23 deletions

View File

@@ -59,10 +59,10 @@ EXPOSE 8043 8013 8080 22
ENTRYPOINT ["/tini", "--"]
CMD /start_development.sh
RUN touch /venv/awx/lib/python2.7/site-packages/awx.egg-link
RUN chmod g+rwx /venv/awx/lib/python2.7/site-packages/awx.egg-link
# Pre-create things that we need to write to
RUN for dir in /var/lib/awx/ /projects /.ansible /var/log/nginx /var/lib/nginx /.local; \
do mkdir -p $dir; chmod -R g+rwx $dir; chgrp -R root $dir; done
RUN chmod g+w /etc/passwd
RUN mkdir -p /projects && chmod g+w /projects
USER ${UID}
RUN for file in /etc/passwd /supervisor.conf \
/venv/awx/lib/python2.7/site-packages/awx.egg-link /var/run/nginx.pid; \
do touch $file; chmod -R g+rwx $file; chgrp -R root $file; done

View File

@@ -1,6 +1,12 @@
#!/bin/bash
set +x
if [ `id -u` -ge 500 ] || [ -z "${CURRENT_UID}" ]; then
echo "awx:x:`id -u`:`id -g`:,,,:/tmp:/bin/bash" >> /tmp/passwd
cat /tmp/passwd > /etc/passwd
rm /tmp/passwd
fi
# Wait for the databases to come up
ansible -i "127.0.0.1," -c local -v -m wait_for -a "host=postgres port=5432" all
ansible -i "127.0.0.1," -c local -v -m wait_for -a "host=memcached port=11211" all

View File

@@ -1,4 +1,3 @@
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;

View File

@@ -1,12 +1,6 @@
#!/bin/bash
set +x
if [ `id -u` -ge 500 ]; then
echo "awx:x:`id -u`:`id -g`:,,,:/tmp:/bin/bash" >> /tmp/passwd
cat /tmp/passwd > /etc/passwd
rm /tmp/passwd
fi
/bootstrap_development.sh
cd /awx_devel

View File

@@ -1,7 +1,7 @@
#!/bin/bash
set +x
if [ `id -u` -ge 500 ]; then
if [ `id -u` -ge 500 ] || [ -z "${CURRENT_UID}" ]; then
echo "awx:x:`id -u`:`id -g`:,,,:/tmp:/bin/bash" >> /tmp/passwd
cat /tmp/passwd > /etc/passwd
rm /tmp/passwd