|
1 | | -#This workflow automatically takes my code, builds a docker image, and returns the date and time |
2 | | -#This is the name of the workflow - used under the Actions tab |
| 1 | +#This workflow automatically takes my code, builds a docker image, and returns the date and time, which can be validated in the logs |
| 2 | +#This is the name of this workflow |
3 | 3 | name: Go Dockerimage Pipeline |
4 | | -#This is workflow name - will appear in the list of workflow runs |
| 4 | +#This is workflow name |
5 | 5 | run-name: CI/CD Pipeline |
6 | | -#Trigger for the workflow - in otherwords, what causes the workflow to kick off |
| 6 | +#Trigger for the workflow |
7 | 7 | on: |
8 | 8 | push: |
9 | 9 | branches: |
10 | 10 | - main |
11 | 11 | #Groups all jobs associated with this workflow together |
12 | 12 | jobs: |
13 | 13 | build: |
14 | | - #Specifies the type of VM to create and what OS it runs. Docker is already installed |
| 14 | + #Specifies the type of VM OS to run. |
15 | 15 | runs-on: ubuntu-latest |
16 | | - #Steps involved with the jobs the workflow runs |
17 | 16 | steps: |
18 | 17 | #Step1 - Checks out code |
19 | 18 | - name: Checkout code |
20 | | - #Most recent version of actions/checkout - checksout repo to the runner |
| 19 | + #Most recent version of actions/checkout - checksout repo to the runner |
21 | 20 | uses: actions/checkout@v5 |
22 | 21 |
|
23 | | - #Step2 - Setups up Docker |
| 22 | + #Step2 - Builds the Docker image with provided code |
24 | 23 | - name: Docker |
25 | 24 | run: docker build -t gotime . |
26 | 25 |
|
27 | | - #Step3 - Run your container |
| 26 | + #Step3 - Run the container then deletes it once the code has ran |
28 | 27 | - name: Run container and capture output |
29 | 28 | run: docker run --rm gotime |
| 29 | + |
| 30 | + #Step4 - Authenticates to Google Cloud with the existing JSON key |
| 31 | + - name: Authenticate to Google Cloud |
| 32 | + uses: google-github-actions/auth@v3 |
| 33 | + with: |
| 34 | + credentials_json: '${{ secrets.GCP_SA_KEY }}' |
| 35 | + |
| 36 | + #Step5 - Configures Docker to access my GCP project |
| 37 | + - name: Configure Docker to access GCP project |
| 38 | + run: | gcloud auth configure-docker us-west1-docker.pkg.dev |
| 39 | +
|
| 40 | + #Step6 - Tags the container and pushes to the Artifact Repo in my GCP project |
| 41 | + - name: Push to Artifact Registry |
| 42 | + run: | docker tag gotime us-west1-docker.pkg.dev/YOUR_PROJECT/YOUR_REPO/gotime:latest |
| 43 | + docker push us-west1-docker.pkg.dev/YOUR_PROJECT/YOUR_REPO/gotime:latest |
0 commit comments