From 3082f34fd7bf2be3500d4bb8bdf57320a8c8d853 Mon Sep 17 00:00:00 2001 From: ahmed elsayed <74507200+AhmedElsayed98@users.noreply.github.com> Date: Tue, 24 May 2022 23:28:55 +0200 Subject: [PATCH 1/2] Create Dockerfile --- Dockerfile | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0f88e97 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM golang:1.18-alpine3.15 +WORKDIR /app +COPY . . +RUN go build -o main main.go + +EXPOSE 8080 + +CMD [ "/app/main" ] \ No newline at end of file From dbf55cd4cd4d58e178765a7a49e085cbb18b5917 Mon Sep 17 00:00:00 2001 From: ahmed elsayed <74507200+AhmedElsayed98@users.noreply.github.com> Date: Thu, 26 May 2022 00:35:05 +0200 Subject: [PATCH 2/2] integrating jenkins with dockerfile --- Dockerfile | 9 +++++++-- Jenkinsfile | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 Jenkinsfile diff --git a/Dockerfile b/Dockerfile index 0f88e97..9fae6b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,13 @@ + FROM golang:1.18-alpine3.15 WORKDIR /app COPY . . RUN go build -o main main.go - EXPOSE 8080 +CMD [ "/app/main" ] -CMD [ "/app/main" ] \ No newline at end of file +FROM jenkins +COPY https.pem /var/lib/jenkins/cert +COPY https.key /var/lib/jenkins/pk +ENV JENKINS_OPTS --httpPort=-1 --httpsPort=8083 --httpsCertificate=/var/lib/jenkins/cert --httpsPrivateKey=/var/lib/jenkins/pk +EXPOSE 8083 \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..63de6fb --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,27 @@ +pipeline { + agent { docker { image 'golang' } } + + stages { + stage('Build') { + steps { + // Create our project directory. + sh 'cd ${GOPATH}/src' + sh 'mkdir -p ${GOPATH}/src/MY_PROJECT_DIRECTORY' + + // Copy all files in our Jenkins workspace to our project directory. + sh 'cp -r ${WORKSPACE}/* ${GOPATH}/src/MY_PROJECT_DIRECTORY' + + // Copy all files in our "vendor" folder to our "src" folder. + sh 'cp -r ${WORKSPACE}/vendor/* ${GOPATH}/src' + + // Build the app. + sh 'go build' + } + } + + // Each "sh" line (shell command) is a step, + // so if anything fails, the pipeline stops. + stage('Test') { + steps { + // Remove cached test results. + sh 'go clean -cache'