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

Feat/GitHub action #7

Merged
merged 65 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
b4217f3
feat/creating enigma bake command to build, scan and tag in a single …
Bharadwajshivam28 Aug 26, 2024
9005a8a
feat:removed tag code as build command was making tag also
Bharadwajshivam28 Aug 26, 2024
a80f529
feat:Improved readme
Bharadwajshivam28 Aug 26, 2024
717b60c
feat:Added .DS_Store in .gitignore
Bharadwajshivam28 Aug 26, 2024
5fdd642
feat:Added .DS_Store in .gitignore
Bharadwajshivam28 Aug 26, 2024
7973db7
feat:Added .DS_Store in .gitignore
Bharadwajshivam28 Aug 26, 2024
a179a2f
feat:Added .DS_Store in .gitignore
Bharadwajshivam28 Aug 26, 2024
3dbe8e6
feat/created publish command to Push Image on Dockerhub and cleanup i…
Bharadwajshivam28 Aug 26, 2024
854831d
feat/created publish command to Push Image on Dockerhub and cleanup i…
Bharadwajshivam28 Aug 26, 2024
72dbef8
Merge branch 'main' into feat/publish
Bharadwajshivam28 Aug 26, 2024
ff4d236
feat:passed dummy values in readme.md
Bharadwajshivam28 Aug 26, 2024
a45efa4
feat:Publish for aws and gcp also ready
Bharadwajshivam28 Aug 26, 2024
e61ff97
feat:custom workflow for enigma docker
Bharadwajshivam28 Aug 27, 2024
f1fcbb2
feat:custom workflow for enigma docker
Bharadwajshivam28 Aug 27, 2024
9a1b611
feat:custom workflow for enigma docker
Bharadwajshivam28 Aug 27, 2024
1f6d817
feat:custom workflow for enigma docker
Bharadwajshivam28 Aug 27, 2024
82face0
feat:custom workflow for enigma docker
Bharadwajshivam28 Aug 27, 2024
8fd7601
feat:custom workflow for enigma docker
Bharadwajshivam28 Aug 27, 2024
a01b63e
feat:custom workflow for enigma docker
Bharadwajshivam28 Aug 27, 2024
afde9ec
feat:custom workflow for enigma docker
Bharadwajshivam28 Aug 27, 2024
75524b5
feat:custom workflow for enigma docker
Bharadwajshivam28 Aug 27, 2024
a8b8d35
feat:custom workflow for enigma docker
Bharadwajshivam28 Aug 27, 2024
60d26b4
feat:custom workflow for enigma docker
Bharadwajshivam28 Aug 27, 2024
09a5804
feat:custom workflow for enigma docker
Bharadwajshivam28 Aug 27, 2024
2a7a012
removed sarif file in go code
Bharadwajshivam28 Aug 27, 2024
7f5cf0d
commented scan code to test
Bharadwajshivam28 Aug 27, 2024
a0b9ed4
added .enigma file
Bharadwajshivam28 Aug 27, 2024
31b661b
testing workflow
Bharadwajshivam28 Aug 27, 2024
851b1b1
removed /n
Bharadwajshivam28 Aug 27, 2024
a227102
modified code
Bharadwajshivam28 Aug 27, 2024
ab0af22
removed unwanted code
Bharadwajshivam28 Aug 27, 2024
5a52dc7
added aws creds parameters
Bharadwajshivam28 Aug 27, 2024
a50b42b
feat:added aws inputs
Bharadwajshivam28 Aug 27, 2024
03eff5e
modified entrypoint.sh
Bharadwajshivam28 Aug 27, 2024
14f5eb3
changed Dockerfile
Bharadwajshivam28 Aug 27, 2024
c6a7658
modified Dockerfile
Bharadwajshivam28 Aug 27, 2024
242126f
testing by commenting entrypoint.sh
Bharadwajshivam28 Aug 27, 2024
80d2c43
commented some lines
Bharadwajshivam28 Aug 27, 2024
229ac9b
modified full correct Dockerfile and action.yml
Bharadwajshivam28 Aug 27, 2024
59a4027
modified entrypoint.sh
Bharadwajshivam28 Aug 27, 2024
4dd45af
changed entrypoint.sh
Bharadwajshivam28 Aug 27, 2024
b3c5cdd
modfied entry point.sh
Bharadwajshivam28 Aug 27, 2024
eb05cb6
feat:modified action.yml
Bharadwajshivam28 Aug 30, 2024
d82b992
modified scout command
Bharadwajshivam28 Aug 30, 2024
692435c
removed vaues from .enigma
Bharadwajshivam28 Aug 30, 2024
c4ae531
commented cleanup part
Bharadwajshivam28 Aug 30, 2024
e0f4ea0
modified action.yml
Bharadwajshivam28 Aug 30, 2024
bc675b2
modified action.yml
Bharadwajshivam28 Aug 30, 2024
193541e
added aws cli install part
Bharadwajshivam28 Aug 30, 2024
448c491
commented login part from custom workflow
Bharadwajshivam28 Aug 30, 2024
80843ec
added auth part in entrypoint.sh:
Bharadwajshivam28 Aug 30, 2024
8ef329a
commented aws login in entrypoint
Bharadwajshivam28 Aug 30, 2024
6a8f03e
added auth part in entrypoint.sh
Bharadwajshivam28 Aug 30, 2024
43ef106
modified entrypoint file
Bharadwajshivam28 Aug 30, 2024
4884c93
added aws in dockerfile
Bharadwajshivam28 Aug 30, 2024
f9df1a5
added aws in dockerfile
Bharadwajshivam28 Aug 30, 2024
c05d581
added cleanup
Bharadwajshivam28 Aug 30, 2024
93e330f
modifed entrypoint.sh
Bharadwajshivam28 Aug 30, 2024
88b9673
modified readme
Bharadwajshivam28 Aug 30, 2024
d2e9400
Merge branch 'main' into feat/github-action
Bharadwajshivam28 Aug 30, 2024
595ab9a
Update entrypoint.sh
Bharadwajshivam28 Aug 30, 2024
d53745c
Update readme.md
Bharadwajshivam28 Aug 30, 2024
e254848
feat: modified entrypoint.sh and release.yml
Bharadwajshivam28 Aug 30, 2024
d593df4
feat:changed tag to v1
Bharadwajshivam28 Aug 30, 2024
e7d619d
feat:changed release.yml file
Bharadwajshivam28 Aug 30, 2024
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 .enigma
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DOCKER_IMAGE
DOCKER_TAG
CLEANUP
DOCKER_IMAGE=
DOCKER_TAG=
CLEANUP=
SCAN=
41 changes: 27 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
ARG GO_VERSION=1.23
FROM golang:${GO_VERSION} as builder
ARG PROGRAM=nothing
ARG VERSION=development
FROM golang:1.23

RUN mkdir /src /output
# Install Docker CLI and other dependencies
RUN apt-get update && apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release \
unzip

WORKDIR /src
# Add Docker's official GPG key
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

COPY . .
RUN GOBIN=/output make install VERSION=$VERSION
RUN PROGRAM=$(ls /output); echo "#!/bin/sh\nexec '/usr/bin/$PROGRAM' \"\$@\"" > /docker-entrypoint.sh && chmod +x /docker-entrypoint.sh
# Set up the Docker repository
RUN echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null

# Install Docker CE CLI
RUN apt-get update && apt-get install -y docker-ce-cli

# Install AWS CLI v2
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
unzip awscliv2.zip && \
./aws/install && \
rm -rf aws awscliv2.zip

FROM gcr.io/distroless/base:latest
ARG PROGRAM=nothing
WORKDIR /go/src/app
COPY . .
RUN go build -o enigma main.go

COPY --from=builder /output/${PROGRAM} /
USER 1000
ENTRYPOINT [""]
ENTRYPOINT ["/go/src/app/entrypoint.sh"]
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
This repo offers to Work effortlessly with Docker, Helm, Docker Compose, Terraform, and other essential DevOps tools. It streamlines your workflow by automating complex commands and managing configurations. Simply set your environment variables, and let Enigma handle rest. With its intuitive design and powerful automation, you’ll achieve greater efficiency and consistency in your DevOps processes.

## 🚀 Table Of Content
1. [Docker](https://github.com/clouddrove/enigma/blob/master/modules/docker/README.md)
1. [Docker](https://github.com/clouddrove/enigma/blob/main/modules/docker/readme.md)

## ✨ Contributors

Expand Down
34 changes: 34 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: 'Enigma Docker Build and Publish'
description: 'Builds, scans, tags, and pushes Docker images using the Enigma tool'
inputs:
command:
description: 'Command to run (bake or publish)'
required: true
DOCKER_IMAGE:
description: 'Docker image name'
required: true
DOCKER_TAG:
description: 'Docker image tag'
required: true
CLEANUP:
description: 'Cleanup after push (true or false)'
required: false
default: 'false'
AWS_REGION:
description: 'AWS Region'
required: true
AWS_ACCOUNT_ID:
description: 'AWS Account ID'
required: true
runs:
using: 'docker'
image: 'Dockerfile'
env:
DOCKER_IMAGE: ${{ inputs.DOCKER_IMAGE }}
DOCKER_TAG: ${{ inputs.DOCKER_TAG }}
AWS_ACCOUNT_ID: ${{ inputs.AWS_ACCOUNT_ID }}
AWS_REGION: ${{ inputs.AWS_REGION }}
CLEANUP: ${{ inputs.AWS_REGION }}

args:
- ${{ inputs.command }}
9 changes: 9 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
set -e

# Check if provider is AWS
if [ "$PROVIDER" = "aws" ]; then
aws ecr get-login-password --region "$AWS_REGION" | docker login --username AWS --password-stdin "$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com"
fi

exec "/go/src/app/enigma" "$@"
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ func main() {
fmt.Println("Unknown command:", command)
fmt.Println("Commands: bake, publish")
}
}
}
10 changes: 9 additions & 1 deletion modules/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,20 @@ func BuildDockerImage() {

fmt.Println("Build complete.")

fmt.Println("Build complete.")
TagDockerImage()
}

// ScanDockerImage performs a security scan of the Docker image and saves the report in SARIF format.
// It uses the `docker scout` command to scan the image for vulnerabilities.
func ScanDockerImage() {
scan := os.Getenv("SCAN")

if scan != "true" {
fmt.Println("SCAN is not set to true. Skipping Docker image scan.")
return
}

dockerTag := os.Getenv("DOCKER_TAG")

if dockerTag == "" {
Expand All @@ -56,6 +64,7 @@ func ScanDockerImage() {
log.Fatalf("Error running docker scout scan: %v", err)
}

fmt.Println("Docker image scan complete.")
fmt.Printf("Scan complete. Report saved to %s\n", sarifFile)
}

Expand Down Expand Up @@ -83,7 +92,6 @@ func TagDockerImage() {
fmt.Println("Docker image tagged successfully.")
}


// PushDockerImage pushes the tagged Docker image to the specified registry and optionally cleans up local images.
// It uses the `docker push` command to upload the image to the registry specified in DOCKER_TAG.
// Cleanup is performed by default or when explicitly set to "true". It's only disabled when set to "false".
Expand Down
41 changes: 39 additions & 2 deletions modules/docker/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
DOCKER_IMAGE=nginx
DOCKER_TAG=xyz:v1
CLEANUP=true
SCAN=false
```

when working on local keep SCAN=true to it scan your image and generate report for it.

3. Add Dockerfile of your in root of the folder

4. Now from root of the folder run:
Expand All @@ -20,12 +23,46 @@ go build -o enigma main.go
```

### To work with Docker commands run-
- To Build, Scan and Tag:
- To Build and Tag:
```
./enigma bake
```

- To Push Image to Registry and cleanup Image at end(Cleanup will be only done if in `.enigma` CLEANUP is set true or by default it will take true):
```
./enigma publish
```
```

## Usage in GitHub Actions
### This GitHub Action builds docker image, tags and pushes to the registry you want.

```yaml
name: Enigma Docker

on:
push:
branches: main

jobs:
login:
runs-on: ubuntu-latest
steps:

- name: Build Docker Image
uses: clouddrove/enigma@main
with:
command: bake
DOCKER_IMAGE: ${{ env.DOCKER_IMAGE }}
DOCKER_TAG: ${{ env.DOCKER_TAG }}
AWS_ACCOUNT_ID: ${{ env.AWS_ACCOUNT_ID }}
AWS_REGION: ${{ env.AWS_REGION }}

- name: Publish Docker Image
uses: clouddrove/enigma@main
with:
command: publish
DOCKER_IMAGE: ${{ env.DOCKER_IMAGE }}
DOCKER_TAG: ${{ env.DOCKER_TAG }}
AWS_ACCOUNT_ID: ${{ env.AWS_ACCOUNT_ID }}
AWS_REGION: ${{ env.AWS_REGION }}
```
Loading