Skip to content

Commit

Permalink
Run Linux docker containers as current user (#1003)
Browse files Browse the repository at this point in the history
  • Loading branch information
ribbanya authored Nov 11, 2023
1 parent ac6fae2 commit 1adba28
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 27 deletions.
1 change: 1 addition & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ make_flags='GENERATE_MAP=1'
build_target="$melee_path/build"
docker run --rm \
--user "$(id -u):$(id -g)" \
--volume "$melee_path:/input:ro" \
--volume "$build_target:/output" \
--env MAKE_FLAGS="$make_flags" \
Expand Down
22 changes: 11 additions & 11 deletions .github/packages/build-linux/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM rust:latest as build-rust
RUN git clone 'https://github.com/InusualZ/dadosod.git' \
&& cd dadosod \
COPY tools/dadosod /dadosod
RUN cd dadosod \
&& cargo build -r

FROM ubuntu:latest AS linux-base
Expand All @@ -9,9 +9,6 @@ COPY --from=ghcr.io/decompals/wibo:latest \
${WIBO_PATH} \
${WIBO_PATH}
COPY requirements.txt /tmp/
COPY --from=build-rust \
/dadosod/target/release/dadosod \
/usr/local/bin/dadosod
ARG DEVKITPRO=/opt/devkitpro
ARG DEVKITPPC=${DEVKITPRO}/devkitPPC
COPY --from=devkitpro/devkitppc:latest \
Expand All @@ -30,23 +27,26 @@ ENV PATH="$DEVKITPPC/bin:$PATH"
COPY .github/packages/build-linux/melee-mwcc /usr/local/bin
RUN chmod +x /usr/local/bin/melee-mwcc

FROM linux-base AS build-linux
ENV MAKE_FLAGS="GENERATE_MAP=1"
FROM linux-base AS linux-rw
VOLUME [ "/input", "/output" ]

FROM linux-rw AS build-linux
ENV MAKE_FLAGS="GENERATE_MAP=1"
COPY .github/packages/build-linux/entrypoint.sh /usr/local/bin
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT entrypoint.sh

FROM linux-base AS gen-pages
VOLUME [ "/input", "/output" ]
FROM linux-rw AS gen-pages
COPY .github/packages/gen-pages/entrypoint.sh /usr/local/bin
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT entrypoint.sh

FROM linux-base AS dump-asm
FROM linux-rw AS dump-asm
ARG SHORT_SHA
ARG TREE_URL
VOLUME [ "/input", "/output" ]
COPY --from=build-rust \
/dadosod/target/release/dadosod \
/usr/local/bin/dadosod
COPY .github/packages/dump-asm/readme.py /usr/local/bin
RUN chmod +x /usr/local/bin/readme.py
COPY .github/packages/dump-asm/entrypoint.sh /usr/local/bin
Expand Down
2 changes: 1 addition & 1 deletion .github/packages/build-linux/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -euox pipefail
set -euo pipefail

git clone /input /tmp/input
cd /tmp/input
Expand Down
2 changes: 1 addition & 1 deletion .github/packages/check-issues/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -euox pipefail
set -euo pipefail

cd /input

Expand Down
4 changes: 2 additions & 2 deletions .github/packages/check-issues/setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
set -e
#!/bin/bash
set -euo pipefail

apt update

Expand Down
2 changes: 1 addition & 1 deletion .github/packages/dump-asm/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -euox pipefail
set -euo pipefail

git clone /input /tmp/input
cd /tmp/input
Expand Down
4 changes: 2 additions & 2 deletions .github/packages/gen-pages/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
set -e
#!/bin/bash
set -euo pipefail

git clone /input /tmp/input
cd /tmp/input
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/build-melee.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ jobs:
env:
MAKE_FLAGS: ${{ matrix.make_flags }}
run: |
output="${{ github.workspace }}/output"
mkdir -p "$output"
docker run --rm \
--volume "$PWD:/input:ro" \
--volume /tmp/output:/output \
--env MAKE_FLAGS="$MAKE_FLAGS" \
--user "$(id -u):$(id -g)" \
--volume "$PWD":/input:ro \
--volume "$output:/output" \
--env MAKE_FLAGS="NON_MATCHING=1" \
"$REGISTRY/$IMAGE"
- name: Upload map
Expand Down Expand Up @@ -182,6 +185,7 @@ jobs:
- name: Check for code issues
run: |
result=$(docker run --rm \
--user "$(id -u):$(id -g)" \
--volume "$PWD:/input:ro" \
"$REGISTRY/$IMAGE")
echo "$result"
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/dump-asm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ jobs:

- name: Dump assembly
run: |
output="${{ github.workspace }}/output"
mkdir -p "$output"
short_sha="$(echo "${{ github.sha }}" | cut -c 1-7)"
tree_url="${{ github.server_url }}/${{ github.repository }}/tree/${{ github.sha }}"
docker run --rm \
--user "$(id -u):$(id -g)" \
--volume "$PWD:/input:ro" \
--volume /tmp/output:/output \
--volume "$output:/output" \
-e SHORT_SHA="$short_sha" \
-e TREE_URL="$tree_url" \
${{ env.REGISTRY }}/${{ env.IMAGE }}
Expand Down
21 changes: 17 additions & 4 deletions .github/workflows/publish-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,44 +64,57 @@ jobs:
- name: Try building Melee (GENERATE_MAP=1)
if: startsWith(matrix.target, 'build-')
run: |
output="${{ github.workspace }}/output/generate_map"
mkdir -p "$output"
docker run --rm \
--user "$(id -u):$(id -g)" \
--volume "$PWD:/input:ro" \
--volume /tmp/output/generate_map:/output \
--volume "$output:/output" \
--env MAKE_FLAGS="GENERATE_MAP=1" \
"$IMAGE:test"
- name: Try building Melee (NON_MATCHING=1)
if: startsWith(matrix.target, 'build-')
run: |
output="${{ github.workspace }}/output/non_matching"
mkdir -p "$output"
docker run --rm \
--user "$(id -u):$(id -g)" \
--volume "$PWD":/input:ro \
--volume /tmp/output/non_matching:/output \
--volume "$output:/output" \
--env MAKE_FLAGS="NON_MATCHING=1" \
"$IMAGE:test"
- name: Try checking for code issues
if: matrix.target == 'check-issues'
run: |
docker run --rm \
--user "$(id -u):$(id -g)" \
--volume "$PWD:/input:ro" \
"$IMAGE:test"
- name: Try generating pages
if: matrix.target == 'gen-pages'
run: |
output="${{ github.workspace }}/output"
mkdir -p "$output"
docker run --rm \
--user "$(id -u):$(id -g)" \
--volume "$PWD:/input:ro" \
--volume /tmp/output:/output \
--volume "$output:/output" \
"$IMAGE:test"
- name: Try dumping assembly
if: matrix.target == 'dump-asm'
run: |
output="${{ github.workspace }}/output"
mkdir -p "$output"
short_sha="$(echo "${{ github.sha }}" | cut -c 1-7)"
tree_url="${{ github.server_url }}/${{ github.repository }}/tree/${{ github.sha }}"
docker run --rm \
--user "$(id -u):$(id -g)" \
--volume "$PWD:/input:ro" \
--volume /tmp/output:/output \
--volume "$output:/output" \
-e SHORT_SHA="$short_sha" \
-e TREE_URL="$tree_url" \
"$IMAGE:test"
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/publish-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ jobs:

- name: Generate pages
run: |
output="${{ github.workspace }}/output"
mkdir -p "$output"
docker run --rm \
--user "$(id -u):$(id -g)" \
--volume "$PWD:/input:ro" \
--volume /tmp/output:/output \
--volume "$output:/output" \
${{ env.REGISTRY }}/${{ env.IMAGE }}
- name: Upload generated pages
Expand Down

0 comments on commit 1adba28

Please sign in to comment.