devcontainer: add doc, user to match host machine, and scripts to build/start
This commit is contained in:
@@ -2,7 +2,20 @@
|
||||
|
||||
FROM alpine:3.22
|
||||
|
||||
RUN apk add build-base git go sqlite shellcheck curl jq bash docker
|
||||
RUN apk add build-base git go sqlite shellcheck curl jq sudo bash docker
|
||||
|
||||
# Busybox `less` doesn't appear to support colors (makes git diff lose color)
|
||||
RUN apk add less
|
||||
|
||||
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin v2.0.2
|
||||
RUN GOBIN=/usr/local/bin go install git.offline-twitter.com/offline-labs/gocheckout@v0.0.2
|
||||
|
||||
# Create a user in the container with the same UID as on the host machine, to avoid ownership conflicts.
|
||||
# The user gets sudo of course.
|
||||
ARG USERNAME
|
||||
ARG UID
|
||||
ARG GID
|
||||
RUN addgroup -g ${GID} ${USERNAME}
|
||||
RUN adduser -D -u ${UID} -G ${USERNAME} ${USERNAME}
|
||||
RUN echo "${USERNAME} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/${USERNAME}
|
||||
USER ${USERNAME}
|
||||
|
||||
9
ops/devcontainer/build.sh
Executable file
9
ops/devcontainer/build.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT_PATH=$(cd "$(dirname "$0")" && pwd)
|
||||
|
||||
sudo docker build \
|
||||
--build-arg USERNAME="$(whoami)" \
|
||||
--build-arg UID="$(id -u)" \
|
||||
--build-arg GID="$(id -g)" \
|
||||
-t gas "$SCRIPT_PATH"
|
||||
12
ops/devcontainer/start.sh
Executable file
12
ops/devcontainer/start.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
sudo docker run --rm -it \
|
||||
-v "$(pwd)":/code \
|
||||
-v "$(go env GOCACHE):/gocache-vol" \
|
||||
-e GOCACHE=/gocache-vol \
|
||||
-v "$(go env GOMODCACHE):/gocache-vol/mod-cache" \
|
||||
-e GOMODCACHE=/gocache-vol/mod-cache \
|
||||
-e GOLANGCI_LINT_CACHE=/gocache-vol/lint-cache \
|
||||
--workdir /code \
|
||||
--net host \
|
||||
gas
|
||||
Reference in New Issue
Block a user