forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
85 additions
and
58 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,71 @@ | ||
name: Docker Image Build | ||
description: Builds Cobalt build docker images. | ||
inputs: | ||
docker_service: | ||
description: "Docker compose service." | ||
required: true | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Checkout files | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 1 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1 | ||
- name: Set env vars | ||
run: | | ||
set -x | ||
tag=${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.ref_name }} | ||
tag=${tag//\//__} | ||
tag="${tag%.1[+,-]}" | ||
echo "FLOATING_TAG=${tag}" >> $GITHUB_ENV | ||
full_git_sha=${{ github.sha }} | ||
short_git_sha="${full_git_sha::7}" | ||
echo "GIT_SHA=${short_git_sha}" >> $GITHUB_ENV | ||
shell: bash | ||
- name: Set Docker Tag | ||
id: set-docker-tag-github | ||
if: ${{ (github.event_name != 'pull_request') || (github.event.pull_request.head.repo.full_name == github.repository) }} | ||
run: | | ||
set -x | ||
echo "DOCKER_TAG=ghcr.io/${{ github.repository }}/${{ inputs.docker_service }}:${GIT_SHA}" >> $GITHUB_ENV | ||
echo "DOCKER_FLOATING_TAG=ghcr.io/${{ github.repository }}/${{ inputs.docker_service }}:${FLOATING_TAG}" >> $GITHUB_ENV | ||
shell: bash | ||
# Handle Google Artifact Registry used for pull requests off forked repos. | ||
- name: Set up Cloud SDK | ||
if: ${{ (github.event_name == 'pull_request') && (github.event.pull_request.head.repo.full_name != github.repository) }} | ||
uses: isarkis/setup-gcloud@40dce7857b354839efac498d3632050f568090b6 # v1.1.1 | ||
- name: Login to GAR and set tag | ||
if: ${{ (github.event_name == 'pull_request') && (github.event.pull_request.head.repo.full_name != github.repository) }} | ||
run: | | ||
# Need to login to GAR to be able to push images created by fork based PR workflows. | ||
PROJECT_NAME=$(gcloud config get-value project) | ||
METADATA="http://metadata.google.internal./computeMetadata/v1" | ||
SVC_ACCT="${METADATA}/instance/service-accounts/default" | ||
ACCESS_TOKEN=$(curl -H 'Metadata-Flavor: Google' ${SVC_ACCT}/token | cut -d'"' -f 4) | ||
printf ${ACCESS_TOKEN} | docker login -u oauth2accesstoken --password-stdin https://gcr.io | ||
full_git_sha=${{ github.sha }} | ||
echo "DOCKER_TAG=us-central1-docker.pkg.dev/${PROJECT_NAME}/${{ inputs.docker_service }}:${GIT_SHA}" >> $GITHUB_ENV | ||
echo "DOCKER_FLOATING_TAG=us-central1-docker.pkg.dev/${PROJECT_NAME}/${{ inputs.docker_service }}:${FLOATING_TAG}" >> $GITHUB_ENV | ||
shell: bash | ||
# Proceed with docker pull, build, tag, and push. | ||
- name: Docker Pull | ||
run: | | ||
docker pull "${DOCKER_TAG}" || true | ||
docker pull "${DOCKER_FLOATING_TAG}" || true | ||
shell: bash | ||
- name: Docker Build | ||
run: docker compose build ${{inputs.docker_service}} | ||
shell: bash | ||
- name: Docker Tag | ||
run: | | ||
docker tag ghcr.io/${{ github.repository }}/${{ inputs.docker_service }}:latest ${DOCKER_TAG} | ||
docker tag ghcr.io/${{ github.repository }}/${{ inputs.docker_service }}:latest ${DOCKER_FLOATING_TAG} | ||
shell: bash | ||
- name: Docker Push | ||
run: | | ||
docker push ${DOCKER_TAG} | ||
docker push ${DOCKER_FLOATING_TAG} | ||
shell: bash |
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