Responsible Software Development: How to Reduce Your Application’s Carbon Footprint?
Practical tips on how developers can actively reduce CO2 emissions by optimizing code, infrastructure, and application architecture.
Today, as Innokrea, we will talk to you about CI/CD and how to use GitHub’s native CI/CD solution – GitHub Actions. If you’re curious about what pipelines are and how they can be used to automate the deployment of your application, we invite you to read on. In the areas of DevOps and DevSecOps, we also recommend our articles on Terraform, CI/CD, and the previous post about SAST, DAST, and SCA.
GIT is software used by the vast majority of developers to manage their code. It allows the creation of software branches and the organization of developers’ work. Code is shared on a remote repository, and several companies offer such services, including GitHub, GitLab, and BitBucket. CI/CD tools (continuous integration and continuous deployment) are software solutions that allow for the automation of managing and deploying written code to clients. There are both external tools like Jenkins or CircleCI, as well as those natively integrated with remote repositories, such as GitLab CI or GitHub Actions. The automated processes within CI/CD are often referred to as workflows or pipelines, and they are usually defined in YAML format.
Figure 1 – Pipeline code in Jenkins, where the Groovy language is used. Source: javacodegeeks.com
To understand GitHub Actions properly, we need to start by explaining a few key concepts related to this technology. These include:
The pipeline definition in GitHub Actions is written using YAML and placed in the .github/workflows folder. This might look like the diagram below.
Figure 2 – Example repository with a defined workflow
Let’s try to create a simple web application project using express.js. We will use the npm package manager and GitHub Actions to demonstrate the capabilities of GitHub Actions. The application will respond to HTTP requests at the main endpoint and will be able to use environment variables provided via the workflow. All files are available for download from our public repository.
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send(process.env.RESPONSE_MESSAGE || 'Hello, World!');
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
The pipeline responsible for installing packages (and later deploying the solution) could look as follows:
name: CI 1 Build
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: npm install
Let’s take a look at the next commands that appear in the above file:
Today, we have introduced you to the topic of GitHub Actions. If you’re curious about what more advanced operations can be performed using Actions, join us next week! See you soon!
https://www.javacodegeeks.com/wp-content/uploads/2021/04/Screenshot-2021-02-13-at-9.07.04-AM.png
Responsible Software Development: How to Reduce Your Application’s Carbon Footprint?
Practical tips on how developers can actively reduce CO2 emissions by optimizing code, infrastructure, and application architecture.
Green ITInnovation
Green IT: How Technology Can Support Environmental Protection?
An introduction to the idea of Green IT – a strategy that combines technology with care for the planet.
Green ITInnovation
CI/CD + Terraform – How to Deploy Your Application on AWS? – Part 2
Learn about the possibilities of GitHub Actions - how to quickly deploy an application using GitHub Actions using AWS and Terraform technologies.
AdministrationProgramming