How to Upload Images Into a Bitbucket Repository
Written by:'
Prasad Jayasinghe,
Tech Lead, Global Wavenet
Prerequisites
· Bitbucket Account
· Container Repository Account (Nexus)
· Kubernetes Cluster
Steps
Commit the code into Bitbucket Repository
Commands
#git add #git commit -m "Pocket-sized Clarification" #git push
Configure the Bitbucket Pipeline
Select the Pipelines tab.
Then it volition let us to select some predefined build templates. But don't worry, your technology not there, still we tin write build script to build the image.
Here nosotros can write the custom build scripts.
I'm using Dockerfile to build the docker paradigm from the committed code, then the build image push button to Nexus repository. Then by using yaml file, I'k deploying the build epitome on the Kubernetes cluster.
Dockerfile
FROM openjdk:8-jdk-alpine ARG JAR_FILE=/target/*.jar COPY ${JAR_FILE} app.jar ENTRYPOINT ["java","-jar","/app.jar"]
deployment.yml fiel
apiVersion: v1 kind: Service metadata: name: coursework-app spec: selector: app: coursework-app ports: - port: 8080 targetPort: 8080 type: LoadBalancer --- apiVersion: apps/v1 kind: Deployment metadata: proper noun: coursework-app spec: selector: matchLabels: app: coursework-app template: metadata: labels: app: coursework-app spec: imagePullSecrets: - proper name: <tag proper name> containers: - name: coursework-app image: <image url Eg: username:image_name:tag> ports: - containerPort: 8080
bitbucket-pipeline.yml
paradigm: maven:3.6.3 pipelines: default: - step: proper noun: Build and Push Wavenet Repository script: - mvn clean install - docker login examination.domain.com --username $NEXUS_USERNAME --password $NEXUX_PASSWORD - docker build -t <username:image_name:tag> . - docker push <username:image_name:tag> services: - docker - step: name: Deploy to Kubernetes deployment: production script: - pipe: atlassian/google-gke-kubectl-run:1.3.1 variables: KEY_FILE: $KUBE_CONFIG PROJECT: "wn-crs" COMPUTE_ZONE: "us-central1-c" CLUSTER_NAME: "cluster-1" KUBECTL_COMMAND: "apply" RESOURCE_PATH: "deployment.yml
This bitbucket-deployment.yml file mainly consist of 2 principal sections:
1) Build
two) Deploy
Build
Under this section, the lawmaking will get build and create the Docker image. And so prototype button to Nexus repository
- mvn clean install - docker login examination.domain.com — username $NEXUS_USERNAME — password $NEXUX_PASSWORD - docker build -t <username:image_name:tag> . - docker push <username:image_name:tag>
Deploy
Under this section by using the pushed image, the script will deploy on the Kubernetes cluster.
- step: name: Deploy to Kubernetes deployment: production script: - piping: atlassian/google-gke-kubectl-run:1.3.1 variables: KEY_FILE: $KUBE_CONFIG PROJECT: "wn-crs" COMPUTE_ZONE: "usa-central1-c" CLUSTER_NAME: "cluster-1" KUBECTL_COMMAND: "apply" RESOURCE_PATH: "deployment.yml
Also in this build script, nosotros can use some variables to maintain the security eg : provide login details.
Configure Surround Variables
Select Repository Settings -> Nether pipelines section we can take the Repository variables.
Surround Variable Details
NEXUS_USERNAME and NEXUS_PASSWORS
These two variables are contained login credentials for nexus repository. This is fully directly forward and we tin user carve up account user proper name and countersign.
KUBE_CONFIG
This variable contains login credentials for Kubernetes Cluster.
Generate KUBE_CONGIG value
First, you need to create the service account in Google Cloud
Login to google cloud console -> become to IAM and Admin section -> Select Service business relationship
Once you enter required details then it will ask you for Access permission.
There you can select "Kubernetes Engine Admin"
So click on done. Once it is done, we have to generate the key file.
To exercise that click on iii the dots under "Action" section
So select the JSON and click the create link.
And then it will download a fundamental file. To user this key file as KUBE_CONFIG variable we have convert information technology in to base64 format
Linux
base64 -due west 0 < my_ssh_key
Mac
base64 < my_ssh_key
Generated Key file
Now we tin can user this key in KUBE_CONFIG variable.
Once every thing is done. And then we can run our build scripts.
Build Script is running
Bitbucket pipeline run without any issue
Results
Build image pushed to Repository
Pod is created on Kubernetes cluster:
End.
Reference
- ButbucketCreatinga nd managing service account keys |Cloud IAM DOcumentaion
- Variables & sectret | Bitbucket Cloud | Atlassian Support
READ More
bardwellmosperwrongs.blogspot.com
Source: https://www.globalwavenet.com/2021/01/20/codeblog01/
0 Response to "How to Upload Images Into a Bitbucket Repository"
Post a Comment