If you have built your docker container image and want to deploy a web service, then you need to push your image up to some image repository. Think; GitHub for images.
I prefer github actions, and deploying each time we push to the main branch.
You might need to configure your cloud provider's image repository manually before pushing images to. For GCP, we need to create a Service Account manifest first (JSON content).
This is the part of my github action that pushes the image:
name: Push Image
on:
push:
branches:
- "main"
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
# Replace monadium with the name of your image.
IMAGE_URL: eu.gcr.io/${{ secrets.GCP_PROJECT_ID }}/monadium:${{ github.sha }}
jobs:
ci:
runs-on: ubuntu-20.04
steps:
- name: Checkout repo
uses: actions/checkout@v2
# This will change depending on your cloud provider. Main thing is that docker is configured to use the auth credentials from your cloud provider.
- name: Setup GCP
uses: google-github-actions/setup-gcloud@master
with:
project_id: ${{ env.GCP_PROJECT_ID }}
service_account_key: ${{ env.GCP_SA_KEY }}
export_default_credentials: true
- name: Setup Docker For GCP
run: |
gcloud auth configure-docker -q
# Build the application outside your docker image. Cargo build is Rust's build command. Change it to what your language requires.
- name: Cargo Build
run: cargo build --release
# This will copy the built artefact(s) into the image.
- name: Docker Build
run: docker build -t $IMAGE_URL .
# You can now push to the image repository.
- name: Docker Push
run: docker push $IMAGE_URL
There are a lot of other ways to push images, but I like the fact that most of this code works the same for all cloud providers, and usually works the same way locally if you need to debug.
Top comments (0)