Skip to content

Commit 359ae6c

Browse files
authored
feat: run as user
1 parent 13d5086 commit 359ae6c

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ ENV PRIVILEGED=false
3535
ENV INTERACTIVE=false
3636
ENV DOLLAR=$
3737

38-
COPY Vagrant.file /
38+
COPY Vagrantfile /Vagrantfile.tmp
3939
COPY startup.sh /
4040
RUN chmod +x startup.sh
4141

42-
ENTRYPOINT ["/startup.sh"]
43-
CMD ["/bin/bash"]
42+
CMD ["/startup.sh"]

Vagrant.file renamed to Vagrantfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ Vagrant.configure("2") do |config|
3232
Resize-Partition -DriveLetter "C" -Size (Get-PartitionSupportedSize -DriveLetter "C").SizeMax
3333
# Enable too long paths
3434
New-ItemProperty -Path "HKLM:\\SYSTEM\\CurrentControlSet\\Control\\FileSystem" -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
35+
$username = "VAGRANTVM\\vagrant"
36+
$password = "vagrant"
37+
$credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))
3538
# github actions
3639
Invoke-WebRequest -Uri ${GITHUB_RUNNER_URL} -OutFile ${GITHUB_RUNNER_FILE}
3740
Remove-Item -Path C:\\runner-* -Recurse -Force
@@ -41,6 +44,7 @@ Vagrant.configure("2") do |config|
4144
Expand-Archive -LiteralPath ${GITHUB_RUNNER_FILE} -DestinationPath runner-$random -Force;
4245
Invoke-Expression -Command "C:\\runner-$random\\config.cmd --name ${GITHUB_RUNNER_NAME}_$random --replace --unattended --url ${ORGANIZATION_URL} --labels ${GITHUB_RUNNER_LABELS} --pat ${PAT}";
4346
Start-Process "C:\\runner-$random\\run.cmd";
47+
Start-Process powershell.exe "C:\\runner-$random\\run.cmd" -Credential ($credentials) ;
4448
}
4549
SHELL
4650
end

startup.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
set -eou pipefail
55
# Replace environmental variable to Vagrandfile
66
export RANDOM_STR=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1)
7-
envsubst \
8-
'${PRIVILEGED},${INTERACTIVE},${MEMORY},${CPU},${DISK_SIZE},${GITHUB_RUNNER_FILE},${GITHUB_RUNNER_NAME},${RANDOM_STR},${RUNNERS},${GITHUB_RUNNER_LABELS},${ORGANIZATION_URL},${PAT},${GITHUB_RUNNER_URL}' \
9-
< Vagrant.file > Vagrantfile
107

11-
rm -rf Vagrant.file
8+
if [ ! -f Vagrantfile ]
9+
then
10+
envsubst \
11+
'${PRIVILEGED},${INTERACTIVE},${MEMORY},${CPU},${DISK_SIZE},${GITHUB_RUNNER_FILE},${GITHUB_RUNNER_NAME},${RANDOM_STR},${RUNNERS},${GITHUB_RUNNER_LABELS},${ORGANIZATION_URL},${PAT},${GITHUB_RUNNER_URL}' \
12+
< Vagrantfile.tmp > Vagrantfile
13+
fi
1214

1315
chown root:kvm /dev/kvm
1416

0 commit comments

Comments
 (0)