Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c293e9d

Browse files
authored
[CI] Change docker user to ec2-user (#2834)
Add back in an explicitly defined user in the docker build because I can't figure out which user is being used by the docker image. If a user other than ec2-user is being used, then it is not possibly for the next job to clean up files from previous jobs because it lacks permission. Should fix the problems like https://github.com/pytorch/tutorials/actions/runs/8635938916/job/23674817847 ``` Cleaning the repository Warning: Unable to clean or reset the repository. The repository will be recreated instead. Deleting the contents of '/home/ec2-user/actions-runner/_work/tutorials/tutorials' Error: File was unable to be removed Error: EACCES: permission denied, unlink '/home/ec2-user/actions-runner/_work/tutorials/tutorials/.jenkins/__pycache__/get_files_to_run.cpython-310.pyc' ```
1 parent b41139d commit c293e9d

5 files changed

Lines changed: 36 additions & 5 deletions

File tree

.ci/docker/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ ENV DEBIAN_FRONTEND noninteractive
77
COPY ./common/install_base.sh install_base.sh
88
RUN bash ./install_base.sh && rm install_base.sh
99

10+
# Setup user
11+
# TODO: figure out how to remove this part
12+
COPY ./common/install_user.sh install_user.sh
13+
RUN bash ./install_user.sh && rm install_user.sh
14+
1015
COPY ./common/install_docs_reqs.sh install_docs_reqs.sh
1116
RUN bash ./install_docs_reqs.sh && rm install_docs_reqs.sh
1217

@@ -20,4 +25,5 @@ COPY ./common/install_conda.sh install_conda.sh
2025
COPY ./common/common_utils.sh common_utils.sh
2126
RUN bash ./install_conda.sh && rm install_conda.sh common_utils.sh /opt/conda/requirements.txt
2227

28+
USER ci-user
2329
CMD ["bash"]

.ci/docker/common/common_utils.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ as_ci_user() {
77
# NB: Pass on PATH and LD_LIBRARY_PATH to sudo invocation
88
# NB: This must be run from a directory that the user has access to,
99
# works around https://github.com/conda/conda-package-handling/pull/34
10-
sudo -E -H env -u SUDO_UID -u SUDO_GID -u SUDO_COMMAND -u SUDO_USER env "PATH=$PATH" "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" $*
10+
sudo -E -H -u ci-user env -u SUDO_UID -u SUDO_GID -u SUDO_COMMAND -u SUDO_USER env "PATH=$PATH" "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" $*
1111
}
1212

1313
conda_install() {

.ci/docker/common/install_conda.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ if [ -n "$ANACONDA_PYTHON_VERSION" ]; then
1212
CONDA_FILE="Miniconda3-latest-Linux-x86_64.sh"
1313

1414
mkdir -p /opt/conda
15+
chown ci-user:ci-user /opt/conda
1516

1617
source "$(dirname "${BASH_SOURCE[0]}")/common_utils.sh"
1718

.ci/docker/common/install_user.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
# Copied from https://github.com/pytorch/executorch/blob/6e431355a554e5f84c3a05dfa2b981ead90c2b48/.ci/docker/common/install_user.sh#L1
9+
10+
set -ex
11+
12+
# Same as ec2-user
13+
echo "ci-user:x:1000:1000::/var/lib/ci-user:" >> /etc/passwd
14+
echo "ci-user:x:1000:" >> /etc/group
15+
# Needed on Focal or newer
16+
echo "ci-user:*:19110:0:99999:7:::" >> /etc/shadow
17+
18+
# Create $HOME
19+
mkdir -p /var/lib/ci-user
20+
chown ci-user:ci-user /var/lib/ci-user
21+
22+
# Allow sudo
23+
echo 'ci-user ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/ci-user
24+
25+
# Test that sudo works
26+
sudo -u ci-user sudo -v

.github/workflows/build-tutorials.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ jobs:
9393
"${DOCKER_IMAGE}"
9494
)
9595
96-
docker exec -t "${container_name}" sh -c ".jenkins/build.sh"
96+
docker exec -u ci-user -t "${container_name}" sh -c ".jenkins/build.sh"
9797
9898
- name: Teardown Linux
9999
uses: pytorch/test-infra/.github/actions/teardown-linux@main
@@ -162,9 +162,7 @@ jobs:
162162
"${DOCKER_IMAGE}"
163163
)
164164
165-
docker exec -u root -i "${container_name}" bash
166-
167-
docker exec -t "${container_name}" sh -c ".jenkins/build.sh"
165+
docker exec -u ci-user -t "${container_name}" sh -c ".jenkins/build.sh"
168166
169167
- name: Upload docs preview
170168
uses: seemethere/upload-artifact-s3@v5

0 commit comments

Comments
 (0)