Skip to content

Commit 7993d3e

Browse files
author
Samyak Rout
committed
Updated the dockerfile and the ci pipeline for quick test
1 parent bf1dc05 commit 7993d3e

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: CI Docker Build and Push for Terraform Generator
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- develop
8+
pull_request:
9+
branches:
10+
- main
11+
- develop
12+
workflow_dispatch: # Manual trigger
13+
inputs:
14+
RELEASE_VERSION:
15+
description: 'Release version (e.g., 1.0.0). The "v" prefix will be automatically added.'
16+
required: false
17+
default: ''
18+
19+
jobs:
20+
ci-build:
21+
name: CI Docker Build
22+
runs-on: ubuntu-latest
23+
if: github.event_name != 'workflow_dispatch' # Only run on push or PR, skip manual dispatch
24+
25+
steps:
26+
# Step 1: Checkout the repository
27+
- name: Checkout Repository
28+
uses: actions/checkout@v3
29+
30+
# Step 2: Set up Docker Image Tag
31+
- name: Set up Docker Image Tag
32+
id: tag_step
33+
run: |
34+
DATE_TAG="v$(date +'%Y.%m.%d')"
35+
# Create a default tag for CI builds that isn't meant to be pushed
36+
NEW_TAG="${DATE_TAG}-ci"
37+
echo "Docker Tag: ${NEW_TAG}"
38+
echo "tag=${NEW_TAG}" >> "$GITHUB_OUTPUT"
39+
40+
# Step 3: Build Docker Image (without push)
41+
- name: Build Docker Image (No Push)
42+
uses: docker/build-push-action@v5
43+
with:
44+
file: ./infra_as_code/terraform_generator/backend/Dockerfile # Path to the single Dockerfile
45+
context: ./infra_as_code/terraform_generator/backend
46+
push: false
47+
tags: |
48+
sam123ben/terraform-generator:${{ steps.tag_step.outputs.tag }}
49+
50+
manual-build-push:
51+
name: Manual Docker Build and Push
52+
runs-on: ubuntu-latest
53+
if: github.event_name == 'workflow_dispatch' # Only run on manual trigger
54+
55+
steps:
56+
# Step 1: Checkout the repository
57+
- name: Checkout Repository
58+
uses: actions/checkout@v3
59+
60+
# Step 2: Validate Release Version
61+
- name: Validate Release Version
62+
run: |
63+
if [ -z "${{ github.event.inputs.RELEASE_VERSION }}" ]; then
64+
echo "Error: Please provide a valid release version for manual build and push."
65+
exit 1
66+
fi
67+
68+
# Step 3: Log in to Docker Hub using the Access Token
69+
- name: Log in to Docker Hub
70+
uses: docker/login-action@v2
71+
with:
72+
username: ${{ secrets.DOCKER_USERNAME }}
73+
password: ${{ secrets.DOCKER_HUB_PAT_TOKEN }}
74+
75+
# Step 4: Build and Push Docker Image
76+
- name: Build and Push Docker Image
77+
uses: docker/build-push-action@v5
78+
with:
79+
file: ./infra_as_code/terraform_generator/backend/Dockerfile # Path to the single Dockerfile
80+
context: ./infra_as_code/terraform_generator/backend
81+
push: true
82+
tags: |
83+
sam123ben/terraform-generator:latest
84+
sam123ben/terraform-generator:${{ github.event.inputs.RELEASE_VERSION }}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Use the official Golang image as the base image for building the application
2+
FROM golang:1.23.3 as builder
3+
4+
# Set the working directory
5+
WORKDIR /app
6+
7+
# Copy the Go modules manifests and download dependencies
8+
COPY go.mod go.sum ./
9+
RUN go mod download
10+
11+
# Copy the application source code
12+
COPY . .
13+
14+
# Build the Go application
15+
RUN go build -o terraform-app main.go
16+
17+
# Use a lightweight base image for the runtime
18+
FROM debian:bullseye-slim
19+
20+
# Set the working directory in the container
21+
WORKDIR /app
22+
23+
# Install necessary dependencies, including Terraform
24+
RUN apt-get update && \
25+
apt-get install -y wget unzip && \
26+
wget https://releases.hashicorp.com/terraform/1.5.7/terraform_1.5.7_linux_amd64.zip && \
27+
unzip terraform_1.5.7_linux_amd64.zip -d /usr/local/bin/ && \
28+
rm terraform_1.5.7_linux_amd64.zip && \
29+
apt-get clean && \
30+
rm -rf /var/lib/apt/lists/*
31+
32+
# Copy the built application from the builder stage
33+
COPY --from=builder /app/terraform-app /app/terraform-app
34+
35+
# Copy necessary configuration files and templates
36+
COPY configs/ /app/configs/
37+
COPY templates/ /app/templates/
38+
39+
# Expose any required ports (if applicable)
40+
# EXPOSE 8080
41+
42+
# Set the entrypoint to the application binary
43+
ENTRYPOINT ["/app/terraform-app"]

0 commit comments

Comments
 (0)