generated from DFE-Digital/govuk-rails-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create an action that pushes to DockerHub
Previously there was some duplication between the deployment workflows, each created a separate Docker images and pushed them to Dockerhub. Before the move to Azure we want the Docker images to be pushed to GitHub's container registry (as we'll have fewer sets of credentials to manage). So, instead of implementing it four times I've moved the Docker image steps to their own action and called it from each workflow.
- Loading branch information
1 parent
48cec5c
commit 13c7e6d
Showing
5 changed files
with
95 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: Build and push Docker image | ||
description: Builds a Docker image and pushes it to Dockerhub and GitHub container registry | ||
|
||
inputs: | ||
dockerhub-username: | ||
description: CPD dockerhub account username | ||
required: true | ||
dockerhub-password: | ||
description: CPD dockerhub account password | ||
required: true | ||
account: | ||
description: DockerHub account, the part of the org/app:tag before the colon | ||
required: true | ||
tag: | ||
description: Tag for the Docker image | ||
required: true | ||
github-token: | ||
description: GitHub access token | ||
required: true | ||
|
||
outputs: | ||
docker_image_id: | ||
description: The Docker image ID returned by the build step | ||
value: ${{ steps.docker_build_push.outputs.digest }} | ||
|
||
runs: | ||
using: composite | ||
|
||
steps: | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ inputs.dockerhub-username }} | ||
password: ${{ inputs.dockerhub-password }} | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ inputs.github-token }} | ||
|
||
- name: Build and push docker image | ||
uses: docker/build-push-action@v3 | ||
id: docker_build_push | ||
with: | ||
context: . | ||
build-args: | | ||
BUILDKIT_INLINE_CACHE=1 | ||
GIT_COMMIT_SHA=${{ github.sha }} | ||
push: true | ||
tags: | | ||
${{ inputs.account }}:${{ inputs.tag }} | ||
ghcr.io/dfe-digital/npq-registration:${{ github.event.pull_request.head.sha }} | ||
provenance: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters