diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9fae6b9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ + +FROM golang:1.18-alpine3.15 +WORKDIR /app +COPY . . +RUN go build -o main main.go +EXPOSE 8080 +CMD [ "/app/main" ] + +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'