Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install gh and latest version of go tools #46

Merged
merged 8 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/trivy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ jobs:
contents: write # for actions/checkout to fetch code and for SBOM to push results
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
runs-on: "ubuntu-20.04"
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7
with:
disable-sudo: true
egress-policy: audit

- name: Log into registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
Expand All @@ -62,7 +63,7 @@ jobs:
severity: 'CRITICAL,HIGH'
env:
TRIVY_DB_REPOSITORY: ghcr.io/aquasecurity/trivy-db,public.ecr.aws/aquasecurity/trivy-db
ENV TRIVY_JAVA_DB_REPOSITORY: ghcr.io/aquasecurity/trivy-java-db,public.ecr.aws/aquasecurity/trivy-java-db
TRIVY_SKIP_JAVA_DB_UPDATE: true

- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@662472033e021d55d94146f66f6058822b0b39fd
Expand All @@ -81,7 +82,7 @@ jobs:
scanners: "vuln"
env:
TRIVY_DB_REPOSITORY: ghcr.io/aquasecurity/trivy-db,public.ecr.aws/aquasecurity/trivy-db
ENV TRIVY_JAVA_DB_REPOSITORY: ghcr.io/aquasecurity/trivy-java-db,public.ecr.aws/aquasecurity/trivy-java-db
TRIVY_SKIP_JAVA_DB_UPDATE: true

- name: Upload SBOM to GitHub
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
Expand Down
4 changes: 2 additions & 2 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# See: https://mise.jdx.dev/configuration.html for config options.
# NOTE: Top level tools are installed in home/vscode/config/mise/config.toml during setup.
#[env]
[env]
# supports arbitrary env vars so mise can be used like direnv/dotenv
#EXAMPLE = 'bar'

# specify single or multiple versions of specific tools you want installed for this project.
# Below are examples.
# [tools]
[tools]
# golang = '1.23.1'
# golangci-lint = '1.61.0'
# goreleaser = "2.3.2"
30 changes: 6 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# syntax=docker/dockerfile:1

# See: https://hub.docker.com/r/docker/dockerfile. Syntax directive must be first line
# cspell:ignore FUMPT
# cspell:ignore

# Mise application list and versions are located in
# home/vscode/.config/mise/config.toml
# Add custom Mise tools and version to your projects root as .mist.toml See: https://mise.jdx.dev/configuration.html
# Add custom Mise tools and version to your projects root as .mise.toml See: https://mise.jdx.dev/configuration.html

FROM jdxcode/mise@sha256:412a4b0c307116a7e338aebba5ea3c620bcc3d6d3106ca61f24295a945874bb9 AS mise

Expand All @@ -22,44 +22,26 @@ ENV USERNAME="vscode"
# Copy script libraries for use by internal scripts
COPY usr/bin/lib /usr/bin/lib

# COPY scripts directory
COPY scripts /scripts

# Install packages using the dnf package manager
RUN /scripts/10_install_system_packages.sh

# Install the devcontainers features common-utils scripts from https://github.com/devcontainers/features
# Installs common utilities and the USERNAME user as a non root user
RUN /scripts/20_install_microsoft_dev_container_features.sh
RUN --mount=type=bind,source=scripts/10_install_system_packages.sh,target=/10.sh,ro bash -c "/10.sh"

# Set current user to the vscode user, run all future commands as this user.
USER vscode

# Copy the mise binary from the mise container
COPY --from=mise /usr/local/bin/mise /usr/local/bin/mise

# Install applications that are scoped to the vscode user
RUN sudo chown vscode /scripts

# Copy just files needed for mise from /home.
COPY --chown=vscode:vscode home/vscode/.config/mise /home/vscode/.config/mise

# These are only used in 30_install_mise.sh so do not need to be ENV vars.
# These are only used in 30_install_mise_packages.sh so do not need to be ENV vars.
ARG MISE_VERBOSE=0
ARG RUST_BACKTRACE=0
# https://github.com/jdx/mise/releases
RUN /scripts/30_install_mise_packages.sh
RUN --mount=type=bind,source=scripts/20_install_mise_packages.sh,target=/20.sh,ro bash -c "/20.sh"

# https://github.com/go-delve/delve/releases
ARG GO_DELVE_DLV_VERSION="1.23.1"
# https://github.com/mvdan/gofumpt/releases
ARG GO_FUMPT_VERSION="0.7.0"
RUN /scripts/40_install_other_apps.sh

RUN sudo rm -rf /scripts
RUN --mount=type=bind,source=scripts/30_install_other_apps.sh,target=/30.sh,ro bash -c "/30.sh"

COPY --chown=vscode:vscode home /home/

COPY usr /usr

# VS Code by default overrides ENTRYPOINT and CMD with default values when executing `docker run`.
Expand Down
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
IMAGE_NAME := ghcr.io/sarg3nt/go-dev-container
IMAGE_TAG := 1.0.4
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD | sed 's/[\/_]/-/g')
CURRENT_DIR := $(shell pwd)

.PHONY: build
build:
docker build -t "$(IMAGE_NAME):$(IMAGE_TAG)-$(GIT_BRANCH)" .

.PHONY: run
run:
docker run --mount type=bind,source="${CURRENT_DIR}",target=/workspaces/working \
-w /workspaces/working -it --rm -u "vscode" \
"$(IMAGE_NAME):$(IMAGE_TAG)-$(GIT_BRANCH)" zsh

.PHONY: push
push:
docker push "$(IMAGE_NAME):$(IMAGE_TAG)-$(GIT_BRANCH)"
1 change: 1 addition & 0 deletions home/vscode/.config/mise/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ golangci-lint = 'latest'
goreleaser = 'latest'
bat = 'latest'
fzf = "latest"
gh = "latest"
gitui = "latest"
helm = "latest"
k9s = "latest"
Expand Down
4 changes: 2 additions & 2 deletions home/vscode/.zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ alias kn="kubens"
alias h="helm"

# shellcheck source=/dev/null
source <(kubectl completion bash)
source <(kubectl completion zsh)
complete -o default -F __start_kubectl k

# kx and kn
Expand All @@ -164,7 +164,7 @@ complete -F _kube_contexts kx
complete -F _kube_namespaces kn

# shellcheck source=/dev/null
source <(helm completion bash)
source <(helm completion zsh)
complete -F __start_helm h
complete -F __start_helm helm

Expand Down
23 changes: 22 additions & 1 deletion scripts/10_install_system_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -euo pipefail
IFS=$'\n\t'

# cSpell:ignore epel socat
# cSpell:ignore epel socat CONFIGUREZSHASDEFAULTSHELL

# Install system packages
main() {
Expand Down Expand Up @@ -67,6 +67,27 @@ main() {
log "Installing xz zip unzip" "green"
dnf install -y xz zip unzip

log "Installing dev container features" "blue"
log "Exporting dev container featrues install.sh config variables." "green"
sarg3nt marked this conversation as resolved.
Show resolved Hide resolved
export CONFIGUREZSHASDEFAULTSHELL=true
export INSTALL_OH_MY_ZSH=true
export UPGRADEPACKAGES=false

log "Making /tmp/source directory" "green"
mkdir /tmp/source
cd /tmp/source

log "Cloning devcontainers features repository" "green"
git clone --depth 1 -- https://github.com/devcontainers/features.git

log "Running install script" "green"
cd /tmp/source/features/src/common-utils/
./install.sh
cd -

dnf -y remove epel-release
dnf -y remove dnf-plugins-core

log "Running dnf autoremove" "green"
dnf autoremove -y

Expand Down
46 changes: 0 additions & 46 deletions scripts/20_install_microsoft_dev_container_features.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ main() {
source "/usr/bin/lib/sh/log.sh"

############ Install mise
log "30_install_mise_packages.sh" "blue"
log "20_install_mise_packages.sh" "blue"

# Mise is installed in the docker file from it's master docker branch.
log "Configuring mise" "green"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ main() {
source "/usr/bin/lib/sh/log.sh"
export PATH="$HOME/.local/share/mise/shims:$HOME/.local/bin/:$PATH"

log "40_install_other_apps.sh" "blue"
log "30_install_other_apps.sh" "blue"

add_go_tools
add_vscode_extensions_cache
Expand All @@ -18,20 +18,14 @@ main() {
install_kubectx_kubens_completions
install_omz_plugins
clean_up
date >/home/vscode/build_date.txt
date +"%B %d %Y" >/home/vscode/build_date.txt
}

add_go_tools() {
log "Adding Go Tools" "green"
go install "github.com/go-delve/delve/cmd/dlv@v${GO_DELVE_DLV_VERSION}"
go install "mvdan.cc/gofumpt@v${GO_FUMPT_VERSION}"
# gopls is installed by the go plugin
#go install golang.org/x/tools/gopls@latest

# TODO: Find it if this is still needed and remove if not.
#echo "golang:x:999:vscode" | sudo tee -a /etc/group
#sudo chgrp -R 999 /go
#sudo chmod -R g+rwx /go
go install "github.com/go-delve/delve/cmd/dlv@latest"
go install "mvdan.cc/gofumpt@latest"
go install golang.org/x/tools/gopls@latest
}

add_vscode_extensions_cache() {
Expand Down
1 change: 1 addition & 0 deletions usr/local/bin/help
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ main() {
source /usr/bin/lib/sh/colors.sh
echo -e "${BLUE}********************************************************************"
echo -e " Go Dev Container"
echo -e " Build Date: $(cat /home/vscode/build_date.txt)"
echo -e "********************************************************************${NC}"
echo -e "${CYAN}Type \"help\" to display this messsage again.${NC}"
echo -e ""
Expand Down