Skip to content

Commit fe32d6b

Browse files
committed
Add Container build example workflow
1 parent 7269c61 commit fe32d6b

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
# GitHub recommends pinning actions to a commit SHA.
7+
# This workflow is using the SHA commit for the version
8+
# To get a newer version, you will need to update the SHA.
9+
# You can also reference a tag or branch, but the action may change without warning.
10+
name: Container Build Pipeline
11+
12+
# This workflow will run when the Dockerfile is changed on the main branch
13+
# In practice it should also be updated to run when changes are made to the
14+
# codebase included in the Dockerfile so direct changes to that create a new image
15+
on:
16+
push:
17+
paths:
18+
- Dockerfile
19+
branches:
20+
- main
21+
22+
# This workflow only needs to read the repository contents
23+
# Explicitly state the read permissions to align with security best practices
24+
permissions:
25+
contents: read
26+
27+
jobs:
28+
container-build-push:
29+
runs-on: ubuntu-latest
30+
steps:
31+
# Checkout the repository contents
32+
- name: Checkout the repo
33+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
34+
# Login to Docker Hub so the image can be pushed
35+
- name: Login to Docker Hub
36+
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
37+
# GitHub secrets are used to provide login information to Docker Hub
38+
# Add DOCKERHUB_USERNAME & DOCKERHUB_TOKEN
39+
# Actions secrets are managed under Secrets and variables in the repos Settings
40+
with:
41+
username: ${{ secrets.DOCKERHUB_USERNAME }}
42+
password: ${{ secrets.DOCKERHUB_TOKEN }}
43+
# A unique image tag is required. This example uses the date and time to provide a tag
44+
# This can be updated to utilize a GitHub release version or something similar
45+
- name: Get current date
46+
id: date
47+
run: echo "date=$(date +'%Y-%m-%d.%H.%M')" >> $GITHUB_OUTPUT
48+
# The last step builds the image with Docker, tags it with the desired name and date tag
49+
# It utilizes the login step to then push the image to Docker Hub to the configured account
50+
- name: Build and push image
51+
uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4
52+
with:
53+
# Provide the current directory as build context
54+
context: .
55+
# Specify where the Dockerfile is located in relation to the repo base path
56+
file: Dockerfile
57+
# Enable the push to docker hub
58+
push: true
59+
# Provide the tags to apply to the image, this example uses the date tag
60+
tags: ncar-rda/container-dev:${{ steps.date.outputs.date }}

0 commit comments

Comments
 (0)