Skip to content

Commit 6c21f19

Browse files
author
natalia.gassis
committed
Adicionar configuração do ambiente DevOps com Docker, KinD e Helm
1 parent 1424902 commit 6c21f19

File tree

5 files changed

+170
-52
lines changed

5 files changed

+170
-52
lines changed

.devcontainer/Dockerfile

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Usar uma imagem base com suporte ao Docker
2+
FROM mcr.microsoft.com/vscode/devcontainers/base:ubuntu-22.04
3+
4+
# Evitar prompts interativos durante a instalação
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
7+
# Instalar dependências básicas
8+
RUN apt-get update && apt-get install -y \
9+
apt-transport-https \
10+
ca-certificates \
11+
curl \
12+
gnupg \
13+
lsb-release \
14+
software-properties-common \
15+
git \
16+
unzip \
17+
jq \
18+
&& rm -rf /var/lib/apt/lists/*
19+
20+
# Instalar Docker CLI
21+
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg \
22+
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list \
23+
&& apt-get update && apt-get install -y docker-ce-cli docker-buildx-plugin docker-compose-plugin \
24+
&& rm -rf /var/lib/apt/lists/*
25+
26+
# Instalar kubectl
27+
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" \
28+
&& chmod +x kubectl \
29+
&& mv kubectl /usr/local/bin/
30+
31+
# Instalar KinD
32+
RUN curl -Lo /usr/local/bin/kind https://kind.sigs.k8s.io/dl/v0.21.0/kind-linux-amd64 \
33+
&& chmod +x /usr/local/bin/kind
34+
35+
# Instalar Helm
36+
RUN curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
37+
38+
# Instalar K9s (cliente Kubernetes TUI)
39+
RUN curl -Lo k9s.tar.gz https://github.com/derailed/k9s/releases/latest/download/k9s_Linux_amd64.tar.gz \
40+
&& tar -xf k9s.tar.gz \
41+
&& mv k9s /usr/local/bin/ \
42+
&& rm k9s.tar.gz LICENSE README.md
43+
44+
# Configurar permissões para o usuário vscode
45+
RUN groupadd docker || true \
46+
&& usermod -aG docker vscode || true \
47+
&& mkdir -p /home/vscode/.kube \
48+
&& chown -R vscode:vscode /home/vscode/.kube
49+
50+
# Criar diretório para configurações do KinD
51+
RUN mkdir -p /home/vscode/.kind \
52+
&& chown -R vscode:vscode /home/vscode/.kind
53+
54+
# Limpar cache
55+
RUN apt-get clean && \
56+
rm -rf /var/lib/apt/lists/*
57+
58+
USER vscode

.devcontainer/devcontainer.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "DevOps Environment",
3+
"build": {
4+
"dockerfile": "Dockerfile"
5+
},
6+
"mounts": [
7+
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind"
8+
],
9+
"customizations": {
10+
"vscode": {
11+
"extensions": [
12+
"ms-azuretools.vscode-docker",
13+
"ms-kubernetes-tools.vscode-kubernetes-tools",
14+
"redhat.vscode-yaml",
15+
"streetsidesoftware.code-spell-checker",
16+
"ms-vscode-remote.remote-containers",
17+
"github.copilot"
18+
],
19+
"settings": {
20+
"terminal.integrated.defaultProfile.linux": "bash",
21+
"terminal.integrated.profiles.linux": {
22+
"bash": {
23+
"path": "/bin/bash"
24+
}
25+
}
26+
}
27+
}
28+
},
29+
"forwardPorts": [
30+
2375, // Docker daemon
31+
6443 // Kubernetes API server (KinD)
32+
],
33+
"postCreateCommand": "bash ./.devcontainer/post-create.sh",
34+
"remoteUser": "vscode"
35+
}

.devcontainer/post-create.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Função para verificar se o Docker está funcionando
6+
check_docker() {
7+
echo "Verificando conectividade com o Docker..."
8+
if ! docker info > /dev/null 2>&1; then
9+
echo "ERRO: Não foi possível conectar ao Docker. Verifique se o socket está mapeado corretamente."
10+
return 1
11+
fi
12+
echo "Conectividade com Docker OK!"
13+
return 0
14+
}
15+
16+
# Função para criar um cluster KinD
17+
create_kind_cluster() {
18+
echo "Criando cluster KinD..."
19+
20+
# Verificar se já existe um cluster com este nome
21+
if kind get clusters 2>/dev/null | grep -q "devcontainer-cluster"; then
22+
echo "Cluster 'devcontainer-cluster' já existe."
23+
return 0
24+
fi
25+
26+
# Configuração do cluster KinD com mapeamento de portas
27+
cat > /tmp/kind-config.yaml << EOF
28+
kind: Cluster
29+
apiVersion: kind.x-k8s.io/v1alpha4
30+
nodes:
31+
- role: control-plane
32+
kubeadmConfigPatches:
33+
- |
34+
kind: InitConfiguration
35+
nodeRegistration:
36+
kubeletExtraArgs:
37+
node-labels: "ingress-ready=true"
38+
extraPortMappings:
39+
- containerPort: 80
40+
hostPort: 80
41+
protocol: TCP
42+
- containerPort: 443
43+
hostPort: 443
44+
protocol: TCP
45+
EOF
46+
47+
kind create cluster --name devcontainer-cluster --config /tmp/kind-config.yaml
48+
49+
echo "Configurando o contexto do kubectl..."
50+
mkdir -p $HOME/.kube
51+
kind get kubeconfig --name devcontainer-cluster > $HOME/.kube/config
52+
53+
return 0
54+
}
55+
56+
# Instalar dependências do projeto
57+
install_project_deps() {
58+
echo "Instalando dependências adicionais do projeto..."
59+
# Adicione comandos adicionais aqui
60+
}
61+
62+
# Execução principal
63+
main() {
64+
echo "Iniciando configuração do ambiente de desenvolvimento..."
65+
66+
if check_docker; then
67+
create_kind_cluster
68+
install_project_deps
69+
echo "Ambiente de desenvolvimento configurado com sucesso!"
70+
else
71+
echo "Falha ao configurar o ambiente de desenvolvimento."
72+
exit 1
73+
fi
74+
}
75+
76+
# Executar o script principal
77+
main

Dockerfile

Lines changed: 0 additions & 30 deletions
This file was deleted.

devcontainer.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)