Skip to content

Commit

Permalink
fix(docker): buildable dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
shakefu committed Jul 19, 2023
1 parent 214c31f commit 884df7a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 24 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.devcontainer/
.git/
.github/
.gitignore
.pre-commit-config.yaml
LICENSE
README.md
TODO.md
tf/
29 changes: 21 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \
rm -rf /usr/share/keyrings/githubcli-archive-keyring.gpg && \
rm /etc/apt/sources.list.d/github-cli.list

# Install Go with GO_VERSION
# TODO: This is incompatible with a multi-arch build
ARG GO_VERSION=1.20.5
RUN curl -fsSL https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz \
-o go${GO_VERSION}.linux-amd64.tar.gz && \
tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz && \
rm go${GO_VERSION}.linux-amd64.tar.gz && \
ln -s /usr/local/go/bin/* /usr/local/bin/

# Do the install in user-space
RUN useradd \
--create-home \
Expand All @@ -41,16 +50,20 @@ ARG GITHUB_TOKEN

# Download latest shakefu/home
# home-*-linux-amd64.tar.gz
RUN export GH_TOKEN="${GITHUB_TOKEN}" && \
export RELEASE_GLOB="home-*-linux-amd64.tar.gz" && \
gh release download --repo shakefu/home --pattern "$RELEASE_GLOB" && \
pwd && \
ls -lah && \
tar -xzf $RELEASE_GLOB && \
rm $RELEASE_GLOB
# RUN export GH_TOKEN="${GITHUB_TOKEN}" && \
# export RELEASE_GLOB="home-*-linux-amd64.tar.gz" && \
# gh release download --repo shakefu/home --pattern "$RELEASE_GLOB" && \
# pwd && \
# ls -lah && \
# tar -xzf $RELEASE_GLOB && \
# rm $RELEASE_GLOB

# Build from source
COPY . .
RUN go build --buildvcs=false .

# Install home
RUN ./home setup
RUN ./home setup --debug

# Revert to our default user directory
WORKDIR /workspaces/home
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ func CliCopyFiles(args *CliArgs)
func CliInstall(args *CliArgs, names ...string)
```

Run all the embedded install scripts or exit. This will run all the install scripts, or a specified list of script names. If there is an error with any script it will exit this process.
CliInstall runs all the embedded install scripts or exit. This will run all the install scripts, or a specified list of script names. If there is an error with any script it will exit this process.

<a name="CliStatus"></a>
## func [CliStatus](<https://github.com/shakefu/home/blob/main/home.go#L327>)
## func [CliStatus](<https://github.com/shakefu/home/blob/main/home.go#L333>)

```go
func CliStatus(args *CliArgs, names ...string)
Expand All @@ -105,7 +105,7 @@ func CliStatus(args *CliArgs, names ...string)


<a name="Run"></a>
## func [Run](<https://github.com/shakefu/home/blob/main/home.go#L392>)
## func [Run](<https://github.com/shakefu/home/blob/main/home.go#L398>)

```go
func Run(command string) int
Expand All @@ -114,7 +114,7 @@ func Run(command string) int
Run invokes a subprocess command from a string using shell splitting.

<a name="RunCommand"></a>
## func [RunCommand](<https://github.com/shakefu/home/blob/main/home.go#L401>)
## func [RunCommand](<https://github.com/shakefu/home/blob/main/home.go#L407>)

```go
func RunCommand(argv []string) int
Expand All @@ -123,7 +123,7 @@ func RunCommand(argv []string) int
RunCommand a subprocess command from a tokenized array of string arguments.

<a name="Targets"></a>
## func [Targets](<https://github.com/shakefu/home/blob/main/home.go#L334>)
## func [Targets](<https://github.com/shakefu/home/blob/main/home.go#L340>)

```go
func Targets(args *CliArgs, names *[]string) (map[string]bool, []string)
Expand Down Expand Up @@ -152,7 +152,7 @@ type CliArgs struct {
```

<a name="Script"></a>
## type [Script](<https://github.com/shakefu/home/blob/main/home.go#L433-L436>)
## type [Script](<https://github.com/shakefu/home/blob/main/home.go#L439-L442>)



Expand All @@ -163,7 +163,7 @@ type Script struct {
```

<a name="Script.Run"></a>
### func \(\*Script\) [Run](<https://github.com/shakefu/home/blob/main/home.go#L454>)
### func \(\*Script\) [Run](<https://github.com/shakefu/home/blob/main/home.go#L460>)

```go
func (script *Script) Run(args ...string) (int, error)
Expand All @@ -172,7 +172,7 @@ func (script *Script) Run(args ...string) (int, error)


<a name="Script.RunOrExit"></a>
### func \(\*Script\) [RunOrExit](<https://github.com/shakefu/home/blob/main/home.go#L438>)
### func \(\*Script\) [RunOrExit](<https://github.com/shakefu/home/blob/main/home.go#L444>)

```go
func (script *Script) RunOrExit(args ...string) int
Expand Down
16 changes: 11 additions & 5 deletions home.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func initColor(color string) {
}
}

// Run all the embedded install scripts or exit.
// CliInstall runs all the embedded install scripts or exit.
// This will run all the install scripts, or a specified list of script names.
// If there is an error with any script it will exit this process.
func CliInstall(args *CliArgs, names ...string) {
Expand Down Expand Up @@ -257,6 +257,7 @@ func CliCopyFiles(args *CliArgs) {

// Get the home directory
home, _ := os.UserHomeDir()
log.Debug("home:", home)
// This has to match the embedded path
base := "files"

Expand Down Expand Up @@ -290,9 +291,14 @@ func CliCopyFiles(args *CliArgs) {
fmt.Println(ansi.Black("dry-run:"), "cp", "\"<embed>/"+name+"\"", "\""+target+"\"")
} else {
err := func() error {
// It's our file, we'll write if we want to
if err := os.Chmod(target, 0o600); err != nil {
return fmt.Errorf("could not chmod target: %w", err)
// Check if the file exists
if _, err := os.Stat(target); err == nil {
// It's our file, we'll write if we want to
if err := os.Chmod(target, 0o600); err != nil {
// This is not a fatal error, we want to continue
// log.Debug("Did not set file permissions: ", err)
return fmt.Errorf("could not chmod target: %w", err)
}
}

// Read the embedded file
Expand Down Expand Up @@ -456,7 +462,7 @@ func (script *Script) Run(args ...string) (int, error) {
data := embeddedFile(script.name)

// Set the script arguments
argv := []string{"-s", "-"}
argv := []string{"-l", "-s", "-"}
argv = append(argv, args...)

// And a shell to run it in
Expand Down
13 changes: 10 additions & 3 deletions install/linux_amd64/02-brew
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ $RUN /bin/bash "$TMP"
# This will ensure we have the correct path in /etc/profile which should get
# picked up by dash hopefully
if ! grep 'linuxbrew' /etc/profile; then
$RUN echo 'PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"' | sudo tee -a /etc/profile
(echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> "$HOME/.profile"
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
$RUN echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' | sudo tee -a /etc/profile
# $RUN echo 'PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"' | sudo tee -a /etc/profile
# $RUN echo "Running brew profile stuff"
# /home/linuxbrew/.linuxbrew/bin/brew shellenv
# (echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> "$HOME/.profile"
# (echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> "$HOME/.dashrc"
# (echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') | sudo tee -a "/etc/dashrc"
# eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
echo "Done"
dash -c 'env | sort'
fi

# Linux homebrew does not have permissions for its lock files in this dir, so we
Expand Down

0 comments on commit 884df7a

Please sign in to comment.