Skip to content

Commit

Permalink
feat: multi-architecture docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
eashanroy7 committed Jun 7, 2024
1 parent 2dd85c7 commit 3964431
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/packer-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ jobs:
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ${{ vars.AWS_REGION }}

- name: Prepare Jenkins Configuration as Code file
- name: Prepare Jenkins Configuration as Code file and DSL job
run: |
sed -i 's/ADMIN_USER/${{ secrets.JENKINS_ADMIN_USER }}/g' jenkins/jenkins-config-as-code.yaml
sed -i 's/ADMIN_PASSWORD/${{ secrets.JENKINS_ADMIN_PASSWORD }}/g' jenkins/jenkins-config-as-code.yaml
sed -i 's/G_PAT/${{ secrets.G_PAT }}/g' jenkins/jenkins-config-as-code.yaml
sed -i 's/G_USERNAME/${{ secrets.G_USERNAME }}/g' jenkins/jenkins-config-as-code.yaml
sed -i 's/DOCKER_TOKEN/${{ secrets.DOCKER_TOKEN }}/g' jenkins/jenkins-config-as-code.yaml
sed -i 's/DOCKER_USERNAME/${{ secrets.DOCKER_USERNAME }}/g' jenkins/jenkins-config-as-code.yaml
sed -i 's/G_USERNAME/${{ secrets.G_USERNAME }}/g' jenkins/build-and-push-static-site.groovy
sed -i 's/DOCKER_USERNAME/${{ secrets.DOCKER_USERNAME }}/g' jenkins/build-and-push-static-site.groovy
sed -i 's/DOCKER_PASSWORD/${{ secrets.DOCKER_PASSWORD }}/g' jenkins/build-and-push-static-site.groovy
sed -i 's/BUILD_NO/${{ github.run_number }}/g' jenkins/build-and-push-static-site.groovy
sed -i 's/DOCKERHUB_REPO/${{ secrets.DOCKERHUB_REPO }}/g' jenkins/build-and-push-static-site.groovy
shell: bash

# - name: Replace placeholders in Jenkins DSL script
Expand Down
29 changes: 15 additions & 14 deletions jenkins/build-and-push-static-site.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,38 @@ pipelineJob('build-and-push-static-site') {
}
definition {
cps {
sandbox : true
script("""
pipeline {
agent any
stages {
stage('Setup buildx for multi-architecture docker images') {
steps {
sh 'mkdir -p ~/.docker/cli-plugins/'
sh 'curl -sL https://github.com/docker/buildx/releases/download/v0.14.1/buildx-v0.14.1.linux-amd64 -o ~/.docker/cli-plugins/docker-buildx'
sh 'chmod +x ~/.docker/cli-plugins/docker-buildx'
sh 'export PATH=$PATH:~/.docker/cli-plugins'
}
}
stage('Checkout Code') {
steps {
// HTTPs URL for GitHub repo
git(url: 'https://github.com/csye7125-su24-team17/static-site.git',
git(url: 'https://github.com/G_USERNAME/static-site.git',
branch: 'main',
credentialsId: 'github-pat')
}
}
stage('Build Docker Image') {
steps {
sh 'docker build -t static-site:latest .'
sh 'docker tag static-site:latest eashanroy7866/static-site:latest'
}
}
stage('Push Docker Avatar') {
stage('Build and push Docker Image using buildx') {
steps {
script {
docker.withRegistry('https://index.docker.io/v1/', 'docker-token') {
sh 'docker push eashanroy7866/static-site:latest'
}
}
sh 'echo DOCKER_PASSWORD | docker login -u DOCKER_USERNAME --password-stdin'
sh 'docker buildx create --use'
sh 'docker buildx build --platform linux/amd64,linux/arm64 -t DOCKER_USERNAME/DOCKERHUB_REPO:BUILD_NO --push .'
sh 'docker logout'
}
}
}
}
""")
sandbox()
}
}
}

0 comments on commit 3964431

Please sign in to comment.