Separate build for GCP
This commit is contained in:
parent
c9ce6e5f2b
commit
e5a928d13d
63
.github/workflows/push-container-gcp.yml
vendored
Normal file
63
.github/workflows/push-container-gcp.yml
vendored
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
name: Reusable container push workflow
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
|
||||||
|
env:
|
||||||
|
REPO: ${{ github.repository }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
push-container:
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
steps:
|
||||||
|
- id: get-id
|
||||||
|
name: Get a unique tag for this build
|
||||||
|
run: |
|
||||||
|
SHA=${{ github.sha }}; BRANCH_NAME=${{ github.base_ref || github.ref_name }};
|
||||||
|
BUILD_ID=$BRANCH_NAME-${SHA:0:8};
|
||||||
|
DOCKER_IMAGE="${{vars.GCP_DOCKER_REGISTRY}}/$REPO:$BUILD_ID"
|
||||||
|
echo "BUILD_ID=$BUILD_ID" >> "$GITHUB_OUTPUT";
|
||||||
|
echo "DOCKER_IMAGE=$DOCKER_IMAGE" >> "$GITHUB_OUTPUT";
|
||||||
|
|
||||||
|
- name: Print build id and image name
|
||||||
|
run: |
|
||||||
|
echo "BUILD_ID: ${{ steps.get-id.outputs.BUILD_ID }}";
|
||||||
|
echo "DOCKER_IMAGE: ${{ steps.get-id.outputs.DOCKER_IMAGE }}";
|
||||||
|
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# ✅ 1) Auth to GCP (this is where your SA key is used)
|
||||||
|
- name: Auth to GCP
|
||||||
|
uses: google-github-actions/auth@v2
|
||||||
|
with:
|
||||||
|
# using your existing secret that contains the SA JSON
|
||||||
|
credentials_json: ${{ secrets.GCP_SA_KEY }}
|
||||||
|
|
||||||
|
# ✅ 2) Install gcloud (no creds here)
|
||||||
|
- name: Set up gcloud
|
||||||
|
uses: google-github-actions/setup-gcloud@v2
|
||||||
|
with:
|
||||||
|
project_id: ${{ vars.GCP_PROJECT_ID }}
|
||||||
|
export_default_credentials: true
|
||||||
|
|
||||||
|
- name: Configure Docker for GAR
|
||||||
|
run: |
|
||||||
|
gcloud auth configure-docker $GCP_REGION-docker.pkg.dev
|
||||||
|
|
||||||
|
- name: Build the container image
|
||||||
|
run: |
|
||||||
|
docker build \
|
||||||
|
--build-arg BUILD_STEP=container \
|
||||||
|
--build-arg PUBLIC_BUILD_VERSION=${{ steps.get-id.outputs.BUILD_ID }} \
|
||||||
|
--file fab/d/actions-build.Dockerfile \
|
||||||
|
--tag ${{ steps.get-id.outputs.DOCKER_IMAGE }} \
|
||||||
|
.;
|
||||||
|
|
||||||
|
- name: Container details
|
||||||
|
run: |
|
||||||
|
IMAGE_SIZE=`docker inspect -f "{{ .Size }}" ${{ steps.get-id.outputs.DOCKER_IMAGE }} | numfmt --to=si`;
|
||||||
|
echo "$IMAGE_SIZE container ${{ steps.get-id.outputs.DOCKER_IMAGE }}";
|
||||||
|
|
||||||
|
- name: Push the container image
|
||||||
|
run: docker push ${{ steps.get-id.outputs.DOCKER_IMAGE }}
|
||||||
56
.github/workflows/push-container.yml
vendored
56
.github/workflows/push-container.yml
vendored
@ -49,58 +49,4 @@ jobs:
|
|||||||
echo "$IMAGE_SIZE container ${{ steps.get-id.outputs.DOCKER_IMAGE }}";
|
echo "$IMAGE_SIZE container ${{ steps.get-id.outputs.DOCKER_IMAGE }}";
|
||||||
|
|
||||||
- name: Push the container image
|
- name: Push the container image
|
||||||
run: docker push ${{ steps.get-id.outputs.DOCKER_IMAGE }}
|
run: docker push ${{ steps.get-id.outputs.DOCKER_IMAGE }}
|
||||||
|
|
||||||
push-container-gcp:
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
steps:
|
|
||||||
- id: get-id
|
|
||||||
name: Get a unique tag for this build
|
|
||||||
run: |
|
|
||||||
SHA=${{ github.sha }}; BRANCH_NAME=${{ github.base_ref || github.ref_name }};
|
|
||||||
BUILD_ID=$BRANCH_NAME-${SHA:0:8};
|
|
||||||
DOCKER_IMAGE="${{vars.GCP_DOCKER_REGISTRY}}/$REPO:$BUILD_ID"
|
|
||||||
echo "BUILD_ID=$BUILD_ID" >> "$GITHUB_OUTPUT";
|
|
||||||
echo "DOCKER_IMAGE=$DOCKER_IMAGE" >> "$GITHUB_OUTPUT";
|
|
||||||
|
|
||||||
- name: Print build id and image name
|
|
||||||
run: |
|
|
||||||
echo "BUILD_ID: ${{ steps.get-id.outputs.BUILD_ID }}";
|
|
||||||
echo "DOCKER_IMAGE: ${{ steps.get-id.outputs.DOCKER_IMAGE }}";
|
|
||||||
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
# ✅ 1) Auth to GCP (this is where your SA key is used)
|
|
||||||
- name: Auth to GCP
|
|
||||||
uses: google-github-actions/auth@v2
|
|
||||||
with:
|
|
||||||
# using your existing secret that contains the SA JSON
|
|
||||||
credentials_json: ${{ secrets.GCP_SA_KEY }}
|
|
||||||
|
|
||||||
# ✅ 2) Install gcloud (no creds here)
|
|
||||||
- name: Set up gcloud
|
|
||||||
uses: google-github-actions/setup-gcloud@v2
|
|
||||||
with:
|
|
||||||
project_id: ${{ vars.GCP_PROJECT_ID }}
|
|
||||||
export_default_credentials: true
|
|
||||||
|
|
||||||
- name: Configure Docker for GAR
|
|
||||||
run: |
|
|
||||||
gcloud auth configure-docker $GCP_REGION-docker.pkg.dev
|
|
||||||
|
|
||||||
- name: Build the container image
|
|
||||||
run: |
|
|
||||||
docker build \
|
|
||||||
--build-arg BUILD_STEP=container \
|
|
||||||
--build-arg PUBLIC_BUILD_VERSION=${{ steps.get-id.outputs.BUILD_ID }} \
|
|
||||||
--file fab/d/actions-build.Dockerfile \
|
|
||||||
--tag ${{ steps.get-id.outputs.DOCKER_IMAGE }} \
|
|
||||||
.;
|
|
||||||
|
|
||||||
- name: Container details
|
|
||||||
run: |
|
|
||||||
IMAGE_SIZE=`docker inspect -f "{{ .Size }}" ${{ steps.get-id.outputs.DOCKER_IMAGE }} | numfmt --to=si`;
|
|
||||||
echo "$IMAGE_SIZE container ${{ steps.get-id.outputs.DOCKER_IMAGE }}";
|
|
||||||
|
|
||||||
- name: Push the container image
|
|
||||||
run: docker push ${{ steps.get-id.outputs.DOCKER_IMAGE }}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user