[devtools,v2,1/1] arch-nspawn: ignore localhost for repository mirror

Message ID 20180723071602.17449-1-list@eworm.de
State New
Headers show
Series
  • [devtools,v2,1/1] arch-nspawn: ignore localhost for repository mirror
Related show

Commit Message

Christian Hesse July 23, 2018, 7:16 a.m. UTC
From: Christian Hesse <mail@eworm.de>

My system has a mirror configuration where only the host can access a
local caching service on localhost. So ignore localhost urls.

Signed-off-by: Christian Hesse <mail@eworm.de>
---
 arch-nspawn.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Erich Eckner July 23, 2018, 7:20 a.m. UTC | #1
On 23.07.2018 09:16, Christian Hesse wrote:
> From: Christian Hesse <mail@eworm.de>
> 
> My system has a mirror configuration where only the host can access a
> local caching service on localhost. So ignore localhost urls.

I'm curious, how this can happen / why this is desirable. Shouldn't the
client be able to access the same network resources as the host?
In general, my feeling is, that it is rather desired to repair the
caching for the client than skipping it.

regards,
deep42thought

> 
> Signed-off-by: Christian Hesse <mail@eworm.de>
> ---
>  arch-nspawn.in | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch-nspawn.in b/arch-nspawn.in
> index b9c846e..020ed71 100644
> --- a/arch-nspawn.in
> +++ b/arch-nspawn.in
> @@ -60,7 +60,7 @@ fi
>  
>  pacconf_cmd=$(command -v pacman-conf || command -v pacconf)
>  # shellcheck disable=2016
> -host_mirror=$($pacconf_cmd --repo extra Server 2> /dev/null | head -1 | sed -r 's#(.*/)extra/os/.*#\1$repo/os/$arch#')
> +host_mirror=$($pacconf_cmd --repo extra Server 2> /dev/null | grep -E -v '(127\.0\.0\.1|localhost)' | head -1 | sed -r 's#(.*/)extra/os/.*#\1$repo/os/$arch#')
>  # shellcheck disable=2016
>  [[ $host_mirror == *file://* ]] && host_mirror_path=$(echo "$host_mirror" | sed -r 's#file://(/.*)/\$repo/os/\$arch#\1#g')
>  
>
Christian Hesse July 23, 2018, 7:48 a.m. UTC | #2
Erich Eckner <arch@eckner.net> on Mon, 2018/07/23 09:20:
> On 23.07.2018 09:16, Christian Hesse wrote:
> > From: Christian Hesse <mail@eworm.de>
> > 
> > My system has a mirror configuration where only the host can access a
> > local caching service on localhost. So ignore localhost urls.  
> 
> I'm curious, how this can happen / why this is desirable. Shouldn't the
> client be able to access the same network resources as the host?
> In general, my feeling is, that it is rather desired to repair the
> caching for the client than skipping it.

The host is running pacredir [0][1], which listens on localhost and redirects
to hosts it found on local network. But pacredir returning 404 is a valid
answer, it just means the file is not available in local network. In this
case pacman just uses the next mirror.

In fact pacredir is accessible form client, but things would break
as it has just this single server configured. There is no fallback to a real
mirror that has all the files required.

[0] https://www.archlinux.org/packages/community/x86_64/pacredir/
[1] https://github.com/eworm-de/pacredir#pacredir
Erich Eckner July 23, 2018, 8:48 a.m. UTC | #3
On 23.07.2018 09:48, Christian Hesse wrote:
> Erich Eckner <arch@eckner.net> on Mon, 2018/07/23 09:20:
>> On 23.07.2018 09:16, Christian Hesse wrote:
>>> From: Christian Hesse <mail@eworm.de>
>>>
>>> My system has a mirror configuration where only the host can access a
>>> local caching service on localhost. So ignore localhost urls.  
>>
>> I'm curious, how this can happen / why this is desirable. Shouldn't the
>> client be able to access the same network resources as the host?
>> In general, my feeling is, that it is rather desired to repair the
>> caching for the client than skipping it.
> 
> The host is running pacredir [0][1], which listens on localhost and redirects
> to hosts it found on local network. But pacredir returning 404 is a valid
> answer, it just means the file is not available in local network. In this
> case pacman just uses the next mirror.
> 
> In fact pacredir is accessible form client, but things would break
> as it has just this single server configured. There is no fallback to a real
> mirror that has all the files required.
> 
> [0] https://www.archlinux.org/packages/community/x86_64/pacredir/
> [1] https://github.com/eworm-de/pacredir#pacredir
> 

So the core problem is, that archbuild - in contrast to pacman - only
considers the first mirror. Wouldn't it be better to drop the "head -n1"
then?

regards,
deep42thought
Christian Hesse July 23, 2018, 9:31 a.m. UTC | #4
Erich Eckner <arch@eckner.net> on Mon, 2018/07/23 10:48:
> On 23.07.2018 09:48, Christian Hesse wrote:
> > Erich Eckner <arch@eckner.net> on Mon, 2018/07/23 09:20:  
> >> On 23.07.2018 09:16, Christian Hesse wrote:  
> >>> From: Christian Hesse <mail@eworm.de>
> >>>
> >>> My system has a mirror configuration where only the host can access a
> >>> local caching service on localhost. So ignore localhost urls.    
> >>
> >> I'm curious, how this can happen / why this is desirable. Shouldn't the
> >> client be able to access the same network resources as the host?
> >> In general, my feeling is, that it is rather desired to repair the
> >> caching for the client than skipping it.  
> > 
> > The host is running pacredir [0][1], which listens on localhost and
> > redirects to hosts it found on local network. But pacredir returning 404
> > is a valid answer, it just means the file is not available in local
> > network. In this case pacman just uses the next mirror.
> > 
> > In fact pacredir is accessible form client, but things would break
> > as it has just this single server configured. There is no fallback to a
> > real mirror that has all the files required.
> > 
> > [0] https://www.archlinux.org/packages/community/x86_64/pacredir/
> > [1] https://github.com/eworm-de/pacredir#pacredir
> >   
> 
> So the core problem is, that archbuild - in contrast to pacman - only
> considers the first mirror. Wouldn't it be better to drop the "head -n1"
> then?

I think that would be fine as well. We need some more justification down the
code, though. Currently $host_mirror is expected to hold just one url.

Patch

diff --git a/arch-nspawn.in b/arch-nspawn.in
index b9c846e..020ed71 100644
--- a/arch-nspawn.in
+++ b/arch-nspawn.in
@@ -60,7 +60,7 @@  fi
 
 pacconf_cmd=$(command -v pacman-conf || command -v pacconf)
 # shellcheck disable=2016
-host_mirror=$($pacconf_cmd --repo extra Server 2> /dev/null | head -1 | sed -r 's#(.*/)extra/os/.*#\1$repo/os/$arch#')
+host_mirror=$($pacconf_cmd --repo extra Server 2> /dev/null | grep -E -v '(127\.0\.0\.1|localhost)' | head -1 | sed -r 's#(.*/)extra/os/.*#\1$repo/os/$arch#')
 # shellcheck disable=2016
 [[ $host_mirror == *file://* ]] && host_mirror_path=$(echo "$host_mirror" | sed -r 's#file://(/.*)/\$repo/os/\$arch#\1#g')