Cake views are just presentation-flavored fragments that fit inside
an application’s layout. For most applications they’re HTML mixed
with PHP, but they may end up as XML, CSV, or even binary data.
Layouts are presentation code that is wrapped around a view, and
can be defined and switched between
if the HTTP method of the
request was POST, try to save the data using the Post model.
DI means that you can declare components very freely and then from any other component, just ask for an instance of it and it will be granted
do test-driven development iteratively in AngularJS!
only do DOM manipulation in a directive
with ngClass we can dynamically update the class;
ngBind allows two-way data binding;
ngShow and ngHide programmatically show or hide an element;
The less DOM manipulation, the easier directives are to test, the easier they are to style, the easier they are to change in the future, and the more re-usable and distributable they are.
still wrong.
Before doing DOM manipulation anywhere in your application, ask yourself if you really need to.
a few things wrong with this
jQuery was never necessary
use angular.element and our component will still work when dropped into a project that doesn't have jQuery.
just use angular.element
the element that is passed to the link function would already be a jQuery element!
directives aren't just collections of jQuery-like functions
Directives are actually extensions of HTML
If HTML doesn't do something you need it to do, you write a directive to do it for you, and then use it just as if it was part of HTML.
think how the team would accomplish it to fit right in with ngClick, ngClass, et al.
Don't even use jQuery. Don't even include it.
ry to think about how to do it within the confines the AngularJS.
In jQuery, selectors are used to find DOM elements and then bind/register event handlers to them.
Views are (declarative) HTML that contain AngularJS directives
Directives set up the event handlers behind the scenes for us and give us dynamic databinding.
Views are tied to models (via scopes). Views are a projection of the model
In AngularJS, think about models, rather than jQuery-selected DOM elements that hold your data.
AngularJS uses controllers and directives (each of which can have their own controller, and/or compile and linking functions) to remove behavior from the view/structure (HTML). Angular also has services and filters to help separate/organize your application.
Think about your models
Think about how you want to present your models -- your views.
using the necessary directives to get dynamic databinding.
Attach a controller to each view (using ng-view and routing, or ng-controller)
Make controllers as thin as possible.
You can do a lot with jQuery without knowing about how JavaScript prototypal inheritance works.
objects carry both persistent data and behavior which
operates on that data
Object-Relational Mapping, commonly referred to as its abbreviation ORM, is
a technique that connects the rich objects of an application to tables in
a relational database management system
Represent associations between these models
Validate models before they get persisted to the database
The idea is that if
you configure your applications in the very same way most of the times then this
should be the default way.
Database Table - Plural with underscores separating words
use the ActiveRecord::Base.table_name= method to specify the table
name
Model Class - Singular with the first letter of each word capitalized
Foreign keys - These fields should be named following the pattern
singularized_table_name_id
Primary keys - By default, Active Record will use an integer column named
id as the table's primary key
created_at
updated_at
(table_name)_count - Used to cache the number of belonging objects on
associations.
Single Table Inheritance (STI)
Object Relational Mapping
class_name.yml
ActiveRecord::Base.primary_key=
CRUD is an acronym for the four verbs we use to operate on data: Create,
Read, Update and Delete.
new method will return a new
object
create will return the object and save it to the database.
Using the new method, an object can be instantiated without being saved
user.save will commit the record to the database
update_all class method
an Active Record object can be destroyed which removes
it from the database
Validation is a very important issue to consider when persisting to database, so
the methods create, save and update take it into account when
running: they return false when validation fails and they didn't actually
perform any operation on database.
a bang counterpart
Active Record callbacks allow you to attach code to certain events in the
life-cycle of your models
Rails keeps track of which files have been committed to the database and
provides rollback features
The mesh provides service discovery, load balancing, encryption, authentication and authorization, support for the circuit breaker pattern, and other capabilities.
The service mesh is usually implemented by providing a proxy instance, called a sidecar, for each service instance
the term service is often used for both the instance definitions and the instances themselves.
Name servers host a domain’s DNS information in a text file called the zone file
Start of Authority (SOA) records
You’ll want to specify at least two name servers. That way, if one of them is down, the next one can continue to serve your DNS information.
Every domain’s zone file contains the admin’s email address, the name servers, and the DNS records.
a zone file, which lists domains and their corresponding IP addresses (and a few other things)
TLD nameserver
ISPs cache a lot of DNS information after they’ve looked it up the first time
Usually caching is a good thing, but it can be a problem if you’ve recently made a change to your DNS information
An A record matches up a domain (or subdomain) to an IP address
point different subdomains to different IP addresses
An AAAA record is just like an A record, but for IPv6 IP addresses.
An AXFR record is a type of DNS record used for DNS replication
used on a slave DNS server to replicate the zone file from a master DNS server
DNS Certification Authority Authorization uses DNS to allow the holder of a domain to specify which certificate authorities are allowed to issue certificates for that domain.
A CNAME record or Canonical Name record matches up a domain (or subdomain) to a different domain.
You should not use a CNAME record for a domain that gets email, because some mail servers handle mail oddly for domains with CNAME records
the target domain for a CNAME record should have a normal A-record resolution
a CNAME record does not function the same way as a URL redirect
A DKIM record or domain keys identified mail record displays the public key for authenticating messages that have been signed with the DKIM protocol
An MX record or mail exchange record sets the mail delivery destination for a domain (or subdomain).
Ideally, an MX record should point to a domain that is also the hostname for its server.
Your MX records don’t necessarily have to point to your Linode. If you’re using a third-party mail service, like Google Apps, you should use the MX records they provide.
Lower numbers have a higher priority
NS records or name server records set the nameservers for a domain (or subdomain).
You can also set up different nameservers for any of your subdomains.
The order of NS records does not matter; DNS requests are sent randomly to the different servers, and if one host fails to respond, another one will be queried.
A PTR record or pointer record matches up an IP address to a domain (or subdomain), allowing reverse DNS queries to function.
PTR records are usually set with your hosting provider. They are not part of your domain’s zone file.
An SOA record or Start of Authority record labels a zone file with the name of the host where it was originally created.
The administrative email address is written with a period (.) instead of an at symbol (<@>).
The single nameserver mentioned in the SOA record is considered the primary master for the purposes of Dynamic DNS and is the server where zone file changes get made before they are propagated to all other nameservers.
An SPF record or Sender Policy Framework record lists the designated mail servers for a domain (or subdomain).
An SPF record for your domain tells other receiving mail servers which outgoing server(s) are valid sources of email, so they can reject spoofed email from your domain that has originated from unauthorized servers.
Your SPF record will have a domain or subdomain, type (which is TXT, or SPF if your name server supports it), and text (which starts with “v=spf1” and contains the SPF record settings).
An SRV record or service record matches up a specific service that runs on your domain (or subdomain) to a target domain.
A TXT record or text record provides information about the domain in question to other resources on the Internet.
One common use of the TXT record is to create an SPF record on nameservers that don’t natively support SPF.
Name servers host a domain’s DNS information in a text file called a zone file.
Start of Authority (SOA) records
specifying DNS records, which match domain names to IP addresses.
Every domain’s zone file contains the domain administrator’s email address, the name servers, and the DNS records.
Your ISP’s DNS resolver queries a root nameserver for the proper TLD nameserver. In other words, it asks the root nameserver, *Where can I find the nameserver for .com domains?*
In actuality, ISPs cache a lot of DNS information after they’ve looked it up the first time.
caching is a good thing, but it can be a problem if you’ve recently made a change to your DNS information
An A record points your domain or subdomain to your Linode’s IP address,
use an asterisk (*) as your subdomain
An AAAA record is just like an A record, but for IPv6 IP addresses.
An AXFR record is a type of DNS record used for DNS replication
DNS Certification Authority Authorization uses DNS to allow the holder of a domain to specify which certificate authorities are allowed to issue certificates for that domain.
A CNAME record or Canonical Name record matches a domain or subdomain to a different domain.
Some mail servers handle mail oddly for domains with CNAME records, so you should not use a CNAME record for a domain that gets email.
MX records cannot reference CNAME-defined hostnames.
Chaining or looping CNAME records is not recommended.
a CNAME record does not function the same way as a URL redirect.
A DKIM record or DomainKeys Identified Mail record displays the public key for authenticating messages that have been signed with the DKIM protocol
DKIM records are implemented as text records.
An MX record or mail exchanger record sets the mail delivery destination for a domain or subdomain.
An MX record should ideally point to a domain that is also the hostname for its server.
Priority allows you to designate a fallback server (or servers) for mail for a particular domain. Lower numbers have a higher priority.
NS records or name server records set the nameservers for a domain or subdomain.
You can also set up different nameservers for any of your subdomains
Primary nameservers get configured at your registrar and secondary subdomain nameservers get configured in the primary domain’s zone file.
The order of NS records does not matter. DNS requests are sent randomly to the different servers
A PTR record or pointer record matches up an IP address to a domain or subdomain, allowing reverse DNS queries to function.
opposite service an A record does
PTR records are usually set with your hosting provider. They are not part of your domain’s zone file.
An SOA record or Start of Authority record labels a zone file with the name of the host where it was originally created.
Minimum TTL: The minimum amount of time other servers should keep data cached from this zone file.
An SPF record or Sender Policy Framework record lists the designated mail servers for a domain or subdomain.
An SPF record for your domain tells other receiving mail servers which outgoing server(s) are valid sources of email so they can reject spoofed mail from your domain that has originated from unauthorized servers.
Make sure your SPF records are not too strict.
An SRV record or service record matches up a specific service that runs on your domain or subdomain to a target domain.
Service: The name of the service must be preceded by an underscore (_) and followed by a period (.)
Protocol: The name of the protocol must be proceeded by an underscore (_) and followed by a period (.)
Port: The TCP or UDP port on which the service runs.
Target: The target domain or subdomain. This domain must have an A or AAAA record that resolves to an IP address.
A TXT record or text record provides information about the domain in question to other resources on the internet.
Your project will continue to use an alternative
CI/CD configuration file if one is found
Auto DevOps works with any Kubernetes cluster;
using the
Docker or Kubernetes
executor, with
privileged mode enabled.
Base domain (needed for Auto Review Apps and Auto Deploy)
Kubernetes (needed for Auto Review Apps, Auto Deploy, and Auto Monitoring)
Prometheus (needed for Auto Monitoring)
scrape your Kubernetes cluster.
project level as a variable: KUBE_INGRESS_BASE_DOMAIN
A wildcard DNS A record matching the base domain(s) is required
Once set up, all requests will hit the load balancer, which in turn will route
them to the Kubernetes pods that run your application(s).
review/ (every environment starting with review/)
staging
production
need to define a separate
KUBE_INGRESS_BASE_DOMAIN variable for all the above
based on the environment.
Continuous deployment to production: Enables Auto Deploy
with master branch directly deployed to production.
Continuous deployment to production using timed incremental rollout
Automatic deployment to staging, manual deployment to production
Auto Build creates a build of the application using an existing Dockerfile or
Heroku buildpacks.
If a project’s repository contains a Dockerfile, Auto Build will use
docker build to create a Docker image.
Each buildpack requires certain files to be in your project’s repository for
Auto Build to successfully build your application.
Auto Test automatically runs the appropriate tests for your application using
Herokuish and Heroku
buildpacks by analyzing
your project to detect the language and framework.
Auto Code Quality uses the
Code Quality image to run
static analysis and other code checks on the current code.
Static Application Security Testing (SAST) uses the
SAST Docker image to run static
analysis on the current code and checks for potential security issues.
Dependency Scanning uses the
Dependency Scanning Docker image
to run analysis on the project dependencies and checks for potential security issues.
License Management uses the
License Management Docker image
to search the project dependencies for their license.
Vulnerability Static Analysis for containers uses
Clair to run static analysis on a
Docker image and checks for potential security issues.
Review Apps are temporary application environments based on the
branch’s code so developers, designers, QA, product managers, and other
reviewers can actually see and interact with code changes as part of the review
process. Auto Review Apps create a Review App for each branch.
Auto Review Apps will deploy your app to your Kubernetes cluster only. When no cluster
is available, no deployment will occur.
The Review App will have a unique URL based on the project ID, the branch or tag
name, and a unique number, combined with the Auto DevOps base domain.
Review apps are deployed using the
auto-deploy-app chart with
Helm, which can be customized.
Your apps should not be manipulated outside of Helm (using Kubernetes directly).
Dynamic Application Security Testing (DAST) uses the
popular open source tool OWASP ZAProxy
to perform an analysis on the current code and checks for potential security
issues.
Auto Browser Performance Testing utilizes the Sitespeed.io container to measure the performance of a web page.
add the paths to a file named .gitlab-urls.txt in the root directory, one per line.
After a branch or merge request is merged into the project’s default branch (usually
master), Auto Deploy deploys the application to a production environment in
the Kubernetes cluster, with a namespace based on the project name and unique
project ID
Auto Deploy doesn’t include deployments to staging or canary by default, but the
Auto DevOps template contains job definitions for these tasks if you want to
enable them.
Apps are deployed using the
auto-deploy-app chart with
Helm.
For internal and private projects a GitLab Deploy Token
will be automatically created, when Auto DevOps is enabled and the Auto DevOps settings are saved.
If the GitLab Deploy Token cannot be found, CI_REGISTRY_PASSWORD is
used. Note that CI_REGISTRY_PASSWORD is only valid during deployment.
If present, DB_INITIALIZE will be run as a shell command within an
application pod as a helm post-install hook.
a post-install hook means that if any deploy succeeds,
DB_INITIALIZE will not be processed thereafter.
DB_MIGRATE will be run as a shell command within an application pod as
a helm pre-upgrade hook.
Once your application is deployed, Auto Monitoring makes it possible to monitor
your application’s server and response metrics right out of the box.
annotate
the NGINX Ingress deployment to be scraped by Prometheus using
prometheus.io/scrape: "true" and prometheus.io/port: "10254"
If you are also using Auto Review Apps and Auto Deploy and choose to provide
your own Dockerfile, make sure you expose your application to port
5000 as this is the port assumed by the
default Helm chart.
While Auto DevOps provides great defaults to get you started, you can customize
almost everything to fit your needs; from custom buildpacks,
to Dockerfiles, Helm charts, or
even copying the complete CI/CD configuration
into your project to enable staging and canary deployments, and more.
If your project has a Dockerfile in the root of the project repo, Auto DevOps
will build a Docker image based on the Dockerfile rather than using buildpacks.
Auto DevOps uses Helm to deploy your application to Kubernetes.
Bundled chart - If your project has a ./chart directory with a Chart.yaml
file in it, Auto DevOps will detect the chart and use it instead of the default
one.
Create a project variable
AUTO_DEVOPS_CHART with the URL of a custom chart to use or create two project variables AUTO_DEVOPS_CHART_REPOSITORY with the URL of a custom chart repository and AUTO_DEVOPS_CHART with the path to the chart.
make use of the HELM_UPGRADE_EXTRA_ARGS environment variable to override the default values in the values.yaml file in the default Helm chart.
specify the use of a custom Helm chart per environment by scoping the environment variable
to the desired environment.
Your additions will be merged with the
Auto DevOps template using the behaviour described for
include
copy and paste the contents of the Auto DevOps
template into your project and edit this as needed.
In order to support applications that require a database,
PostgreSQL is provisioned by default.
Set up the replica variables using a
project variable
and scale your application by just redeploying it!
You should not scale your application using Kubernetes directly.
Some applications need to define secret variables that are
accessible by the deployed application.
Auto DevOps detects variables where the key starts with
K8S_SECRET_ and make these prefixed variables available to the
deployed application, as environment variables.
Auto DevOps pipelines will take your application secret variables to
populate a Kubernetes secret.
Environment variables are generally considered immutable in a Kubernetes
pod.
if you update an application secret without changing any
code then manually create a new pipeline, you will find that any running
application pods will not have the updated secrets.
Variables with multiline values are not currently supported
The normal behavior of Auto DevOps is to use Continuous Deployment, pushing
automatically to the production environment every time a new pipeline is run
on the default branch.
If STAGING_ENABLED is defined in your project (e.g., set STAGING_ENABLED to
1 as a CI/CD variable), then the application will be automatically deployed
to a staging environment, and a production_manual job will be created for
you when you’re ready to manually deploy to production.
If CANARY_ENABLED is defined in your project (e.g., set CANARY_ENABLED to
1 as a CI/CD variable) then two manual jobs will be created:
canary which will deploy the application to the canary environment
production_manual which is to be used by you when you’re ready to manually
deploy to production.
If INCREMENTAL_ROLLOUT_MODE is set to manual in your project, then instead
of the standard production job, 4 different
manual jobs
will be created:
rollout 10%
rollout 25%
rollout 50%
rollout 100%
The percentage is based on the REPLICAS variable and defines the number of
pods you want to have for your deployment.
To start a job, click on the play icon next to the job’s name.
Once you get to 100%, you cannot scale down, and you’d have to roll
back by redeploying the old version using the
rollback button in the
environment page.
With INCREMENTAL_ROLLOUT_MODE set to manual and with STAGING_ENABLED
not all buildpacks support Auto Test yet
When a project has been marked as private, GitLab’s Container
Registry requires authentication when downloading
containers.
Authentication credentials will be valid while the pipeline is running, allowing
for a successful initial deployment.
After the pipeline completes, Kubernetes will no longer be able to access the
Container Registry.
We strongly advise using GitLab Container Registry with Auto DevOps in order to
simplify configuration and prevent any unforeseen issues.
While the *_tag helpers can certainly be used for this task they are somewhat verbose as for each tag you would have to ensure the correct parameter name is used and set the default value of the input appropriately.
For these helpers the first argument is the name of an instance variable and the second is the name of a method (usually an attribute) to call on that object.
must pass the name of an instance variable, i.e. :person or "person", not an actual instance of your model object.