From 8ab3bce57c72f49907b06496432fffdc2a829b6d Mon Sep 17 00:00:00 2001 From: Angel Rivera Date: Fri, 11 Jun 2021 21:03:19 -0400 Subject: [PATCH] update --- .circleci/config.yml | 46 +++++++++++++++++++--------------- Dockerfile | 2 +- README.md | 4 --- terraform/google_cloud/main.tf | 22 ++++++++-------- 4 files changed, 38 insertions(+), 36 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9c42f9e..5ad6c20 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,15 +1,10 @@ version: 2.1 -workflows: - build_test_deploy: - jobs: - - build_test - - deploy: - requires: - - build_test +orbs: + docker: circleci/docker@1.5.0 jobs: build_test: docker: - - image: circleci/python:3.7 + - image: circleci/python:3.9 steps: - checkout - run: @@ -19,21 +14,32 @@ jobs: - run: name: Run Tests command: ~/.local/bin/pytest - deploy: + build_push_docker_image: docker: - - image: circleci/python:3.7 + - image: circleci/python:3.9 steps: - checkout - - setup_remote_docker: - docker_layer_caching: false - run: - name: Build and push Docker image - command: | + name: Build app binary + command: | pip install --user --no-cache-dir -r requirements.txt ~/.local/bin/pyinstaller -F hello_world.py - echo 'export TAG=0.1.${CIRCLE_BUILD_NUM}' >> $BASH_ENV - echo 'export IMAGE_NAME=python-cicd-workshop' >> $BASH_ENV - source $BASH_ENV - docker build -t $DOCKER_LOGIN/$IMAGE_NAME -t $DOCKER_LOGIN/$IMAGE_NAME:$TAG . - echo $DOCKER_PWD | docker login -u $DOCKER_LOGIN --password-stdin - docker push $DOCKER_LOGIN/$IMAGE_NAME + - setup_remote_docker + - docker/check + - docker/build: + image: $DOCKER_LOGIN/$CIRCLE_PROJECT_REPONAME + extra_build_args: "-t $DOCKER_LOGIN/$CIRCLE_PROJECT_REPONAME" + tag: 0.1.<< pipeline.number >> + - docker/push: + image: $DOCKER_LOGIN/$CIRCLE_PROJECT_REPONAME + tag: "latest" + - docker/push: + image: $DOCKER_LOGIN/$CIRCLE_PROJECT_REPONAME + tag: "0.1.<< pipeline.number >>" +workflows: + test_build_deploy: + jobs: + - build_test + - build_push_docker_image: + requires: + - build_test \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 7208c12..3a282eb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7 +FROM python:3.9 RUN mkdir /opt/hello_world/ WORKDIR /opt/hello_world/ diff --git a/README.md b/README.md index 2ebcadc..44b51ae 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,3 @@ # Introduction to CI/CD Workshop This repo hosts the codebase and tutorial for an Introductory CI/CD Workshop. The workshop is designed to demonstrate and explain how to implement a CI/CD pipeline into a codebase. - -## Tutorial - -The tutorial can be found in the `tutorial/` directory of this repo. The [icd_101_guide.md](tutorial/cicd_101_guide.md) file hosts the tutorial content for the hands on portion of this tutorial. diff --git a/terraform/google_cloud/main.tf b/terraform/google_cloud/main.tf index 08244e3..b9e124c 100644 --- a/terraform/google_cloud/main.tf +++ b/terraform/google_cloud/main.tf @@ -1,21 +1,21 @@ variable "project_name" { - type = "string" + type = string default = "cicd-workshops" } variable "port_number" { - type = "string" + type = string default = "5000" } variable "docker_declaration" { - type = "string" + type = string # Change the image: string to match the docker image you want to use default = "spec:\n containers:\n - name: test-docker\n image: 'ariv3ra/python-cicd-workshop'\n stdin: false\n tty: false\n restartPolicy: Always\n" } variable "boot_image_name" { - type = "string" + type = string default = "projects/cos-cloud/global/images/cos-stable-69-10895-62-0" } @@ -25,14 +25,14 @@ data "google_compute_network" "default" { # Specify the provider (GCP, AWS, Azure) provider "google"{ - credentials = "${file("cicd_demo_gcp_creds.json")}" - project = "${var.project_name}" + credentials = file("cicd_demo_gcp_creds.json") + project = var.project_name region = "us-east1-b" } resource "google_compute_firewall" "http-5000" { name = "http-5000" - network = "${data.google_compute_network.default.name}" + network = data.google_compute_network.default.name allow { protocol = "icmp" @@ -40,7 +40,7 @@ resource "google_compute_firewall" "http-5000" { allow { protocol = "tcp" - ports = ["${var.port_number}"] + ports = [var.port_number] } } @@ -55,13 +55,13 @@ resource "google_compute_instance" "default" { boot_disk { auto_delete = true initialize_params { - image = "${var.boot_image_name}" + image = var.boot_image_name type = "pd-standard" } } metadata = { - gce-container-declaration = "${var.docker_declaration}" + gce-container-declaration = var.docker_declaration } labels = { @@ -77,5 +77,5 @@ resource "google_compute_instance" "default" { } output "Public_IP_Address" { - value = "${google_compute_instance.default.network_interface.0.access_config.0.nat_ip}" + value = google_compute_instance.default.network_interface[0].access_config[0].nat_ip }