Giter VIP home page Giter VIP logo

aws-samples / amazon-ec2-mac-instance-jenkins-agent Goto Github PK

View Code? Open in Web Editor NEW
8.0 5.0 3.0 585 KB

This sample contains the example mobile application for the blog post "Unify your iOS mobile app CI/CD pipeline with Amazon EC2 Mac Instances" by Benjamin Meyer. It also contains a CDK to set up a jenkins and jenkins agent as explained in the blog post.

Home Page: https://aws.amazon.com/blogs/compute/unify-your-ios-mobile-app-ci-cd-pipeline-with-amazon-ec2-mac-instances-2/

License: MIT No Attribution

Ruby 10.93% Swift 17.51% JavaScript 10.79% TypeScript 60.77%
cdk mac ios

amazon-ec2-mac-instance-jenkins-agent's Introduction

iOS mobile app CI/CD pipeline with Amazon EC2 Mac Instances

This sample is part of the blog post Unify your iOS mobile app CI/CD pipeline with Amazon EC2 Mac Instances.

In this repository you find two CDK stacks and an Hello World demo application to build with an Amazon EC2 Mac Instance as Jenkins agent.

  1. JenkinsStack - Deploys an Amazon VPC with an Amazon EC2 instance with an Jenkins installed. It also adds an Application Load Balancer in front of the Jenkins.
  2. JenkinsMacAgentStack - Deploys an Amazon EC2 Mac Instance on a dedicated Amazon EC2 Mac Instance host and installs the dependencies to use it as a Jenkins agent

All instances will be set up so that you are required to use AWS Systems Manager Session Manager to connect to the instance. Please note that you are the ssm-user when using the SSM Session Manager. If you want to run brew commands you've to start with su -u ec2-user '/usr/local/bin/brew install <>'

Disclaimer

This project is an example of an deployment and meant to be used for testing and learning purposes only. Do not use it in production.

Be aware that the deployment isn't covered by the AWS free tier. Please use the AWS pricing calculator to an estimation beforehand. Please consider that a Dedicated Host for Amazon EC2 Mac Instaces has a minimum allocation period of 24h before you can release it. For more information, see Amazon EC2 Mac Instances.

Deployment

To deploy the Stacks navigate to the jenkins-cdk folder first.

Deployment of Jenkins

cdk deploy JenkinsStack

The Stack will output the ALB's url to connect to the Jenkins instance.

To get the password for Jenkins, connect to Jenkins using SSM Session Manager and sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Deployment of the Amazon E2 Mac Instance as Jenkins Agent

Before you can deploy the second stack you've to create a dedicated host for the Amazon EC2 Mac Instance. Please Consider that a Dedicated Host for Amazon EC2 Mac Instaces has a minimum allocation period of 24h before you can release it.

Follow the instructions of the Amazon EC2 Mac Instance documentation to allocate a dedicated host. The dedicated host-id and host-az will then be used to deploy the JenkinsMacAgentStack. This stack will run an Amazon EC2 Mac Instance on the dedicated host for the Jenkins agent.

This stack currently only has a AMI Map for us-east-2. If you want to deploy this stack in a different region, please adjust:

machineImage: ec2.MachineImage.genericLinux({
    'us-east-2': 'ami-003fa9ca816bcc80d',
}),

of the jenkins-agent-stack.ts to reflect your region and desired AMI.

Before you deploy please create a ec2-key pair in the region you deploy the agent to. This key pair will be used by the Jenkins to connect to the agent.

To deploy the agent:

cdk deploy JenkinsMacAgentStack --context hostid=<dedicated-host-id> --context hostaz=<dedicated-host-az> --context keypair=<key-pair-name>

Outputs:

  • Agent Instance ID
  • Agent instance private IP to set up the agent from the Jenkins head

Configuration of the Agent

Please follow the steps of the blog post Unify your mobile app CI/CD pipeline on EC2 for the configuration of the Jenkins agent and the Amazon EC2 Mac Instance for building mobile applications and to build the demo HelloWorld demo application.

You can use the Systems Manager Session Manager to establish an ssh tunel so you can use the VNC of the Amazon EC2 Mac instance:

aws ssm start-session --target <mac instance id> --region us-east-2 --document-name AWS-StartPortForwardingSession --parameters '{"portNumber":["5900"], "localPortNumber":["5900"]}'

After this open a second terminal window and run:

open vnc://localhost:5900

Be sure that you set a password on the agent before by using the AWS Systems Manager Session Manager.

sudo passwd ec2-user

If you want to change the screens resolution be sure to follow the guide Modify macOS screen resolution on Mac instances of the documentation.

Clean Up

Destroy the two created stacks:

cdk destroy JenkinsMacAgentStack
cdk destroy JenkinsStack

Follow the instructions to release the dedicated host, Release the Dedicated Host for your Mac instance.

Debugging failing builds

Do debug build issues it's a good first step to SSH to the Amazon EC2 Mac Instance and using the Terminal executing the same commands as the Jenkins would run. This may give further insights.

  • SSH to the Amazon EC2 Mac Instance
  • Clone your project the repository or this Repository
  • run fastlane exec xyz

If you see:

Unable to locate Xcode. Please make sure to have Xcode installed on your machine

  • Open Xcode
  • Navigate to Fiels and Preferences
  • Navigate to Locations -> Command Line Tools
  • [OPTIONAL] sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

If you see this while fastlane creation

xcodebuild: error: The project named "HelloWorld" does not contain a scheme named "HelloWorld". The "-list" option can be used to find the names of the schemes in the projec
  • Go to your xcode select Product > Schemes > Manage Schemes and close it again. Make sure that the xcschemefile has been created in your project at WorkspaceName.xcworkspace/xcshareddata/xcschemes.

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

amazon-ec2-mac-instance-jenkins-agent's People

Contributors

amazon-auto avatar be-meyer avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.