-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: implemented CI #25
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| # CICD using GitHub actions | ||
|
|
||
| name: CI/CD | ||
|
|
||
| # Exclude the workflow to run on changes to the helm chart | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths-ignore: | ||
| - 'helm/**' | ||
| - 'k8s/**' | ||
| - 'README.md' | ||
|
|
||
| jobs: | ||
|
|
||
| build: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Go 1.22 | ||
| uses: actions/setup-go@v2 | ||
| with: | ||
| go-version: 1.22 | ||
|
|
||
| - name: Build | ||
| run: go build -o go-web-app | ||
|
|
||
| - name: Test | ||
| run: go test ./... | ||
|
|
||
| code-quality: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Run golangci-lint | ||
| uses: golangci/golangci-lint-action@v6 | ||
| with: | ||
| version: v1.56.2 | ||
|
|
||
| push: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| needs: build | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v1 | ||
|
|
||
| - name: Login to DockerHub | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
| password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
|
||
| - name: Build and Push action | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| file: ./Dockerfile | ||
| push: true | ||
| tags: ${{ secrets.DOCKERHUB_USERNAME }}/go-web-app:${{github.run_id}} | ||
|
|
||
| update-newtag-in-helm-chart: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| needs: push | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| token: ${{ secrets.TOKEN }} | ||
|
|
||
| - name: Update tag in Helm chart | ||
| run: | | ||
| sed -i 's/tag: .*/tag: "${{github.run_id}}"/' helm/go-web-app-chart/values.yaml | ||
|
|
||
| - name: Commit and push changes | ||
|
Comment on lines
+84
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The current command interprets the - sed -i 's/tag: .*/tag: "${{github.run_id}}"/' helm/go-web-app-chart/values.yaml
+ sed -i "s/^ tag: .*/ tag: \"${{ github.run_id }}\"/" helm/go-web-app-chart/values.yamlOr, better: yq e '.image.tag = strenv(GITHUB_RUN_ID)' -i helm/go-web-app-chart/values.yamlThis keeps the YAML valid even if the line has leading spaces. 🤖 Prompt for AI Agents |
||
| run: | | ||
| git config --global user.email "[email protected]" | ||
| git config --global user.name "rakesh-IT5" | ||
| git add helm/go-web-app-chart/values.yaml | ||
| git commit -m "Update tag in Helm chart" | ||
| git push | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Containerize the go application that we have created | ||
| # This is the Dockerfile that we will use to build the image | ||
| # and run the container | ||
|
|
||
| # Start with a base image | ||
| FROM golang:1.22 as base | ||
|
|
||
| # Set the working directory inside the container | ||
| WORKDIR /app | ||
|
|
||
| # Copy the go.mod and go.sum files to the working directory | ||
| COPY go.mod ./ | ||
|
|
||
| # Download all the dependencies | ||
| RUN go mod download | ||
|
|
||
| # Copy the source code to the working directory | ||
| COPY . . | ||
|
|
||
| # Build the application | ||
| RUN go build -o main . | ||
|
|
||
| ####################################################### | ||
| # Reduce the image size using multi-stage builds | ||
| # We will use a distroless image to run the application | ||
| FROM gcr.io/distroless/base | ||
|
|
||
| # Copy the binary from the previous stage | ||
| COPY --from=base /app/main . | ||
|
|
||
| # Copy the static files from the previous stage | ||
| COPY --from=base /app/static ./static | ||
|
|
||
| # Expose the port on which the application will run | ||
| EXPOSE 8080 | ||
|
|
||
| # Command to run the application | ||
| CMD ["./main"] | ||
|
Comment on lines
+26
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Run as a non-root user for better container hardening
FROM gcr.io/distroless/base
COPY --from=base /main /main
COPY --from=base /app/static ./static
+USER nonroot:nonroot
EXPOSE 8080
CMD ["/main"]Most distroless images ship the
🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # AWS CLI v2 | ||
|
|
||
| This bundle contains a built executable of the AWS CLI v2. | ||
|
|
||
| ## Installation | ||
|
|
||
| To install the AWS CLI v2, run the `install` script: | ||
| ``` | ||
| $ sudo ./install | ||
| You can now run: /usr/local/bin/aws --version | ||
| ``` | ||
| This will install the AWS CLI v2 at `/usr/local/bin/aws`. Assuming | ||
| `/usr/local/bin` is on your `PATH`, you can now run: | ||
| ``` | ||
| $ aws --version | ||
| ``` | ||
|
|
||
|
|
||
| ### Installing without sudo | ||
|
|
||
| If you don't have ``sudo`` permissions or want to install the AWS | ||
| CLI v2 only for the current user, run the `install` script with the `-b` | ||
| and `-i` options: | ||
| ``` | ||
| $ ./install -i ~/.local/aws-cli -b ~/.local/bin | ||
| ``` | ||
| This will install the AWS CLI v2 in `~/.local/aws-cli` and create | ||
| symlinks for `aws` and `aws_completer` in `~/.local/bin`. For more | ||
| information about these options, run the `install` script with `-h`: | ||
| ``` | ||
| $ ./install -h | ||
| ``` | ||
|
|
||
| ### Updating | ||
|
|
||
| If you run the `install` script and there is a previously installed version | ||
| of the AWS CLI v2, the script will error out. To update to the version included | ||
| in this bundle, run the `install` script with `--update`: | ||
| ``` | ||
| $ sudo ./install --update | ||
| ``` | ||
|
|
||
|
|
||
| ### Removing the installation | ||
|
|
||
| To remove the AWS CLI v2, delete the its installation and symlinks: | ||
| ``` | ||
| $ sudo rm -rf /usr/local/aws-cli | ||
| $ sudo rm /usr/local/bin/aws | ||
| $ sudo rm /usr/local/bin/aws_completer | ||
| ``` | ||
| Note if you installed the AWS CLI v2 using the `-b` or `-i` options, you will | ||
| need to remove the installation and the symlinks in the directories you | ||
| specified. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Ensure lint passes before pushing an image
pushcurrently depends only onbuild. Ifgolangci-lintfails, the Docker image will still be published.This blocks publishing on failing quality gates and avoids shipping broken code.
📝 Committable suggestion
🤖 Prompt for AI Agents