Skip to content

Commit

Permalink
fix : docker CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryOkafor committed Jun 1, 2024
1 parent ab99993 commit 8aade00
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 26 deletions.
69 changes: 44 additions & 25 deletions .github/workflows/Docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
env:
DOCKER_IMAGE_NAME_STAGING: jerryokafor/url-shortener
DOCKER_CONTAINER_NAME_STAGING: url-shortner-staging
DOCKER_IMAGE_NAME: jerryokafor/url-shortener
DOCKER_CONTAINER_NAME: url-shortner

steps:
- name: Check out the repo
uses: actions/checkout@v4
Expand Down Expand Up @@ -49,31 +55,44 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

# - name: Setup gcloud Auth
# id: account
# uses: google-github-actions/auth@v2
# with:
# credentials_json: ${{ secrets.GCP_SA_KEY }}

# - name: Setup gcloud CLI
# uses: google-github-actions/setup-gcloud@v2
# with:
# project_id: ${{ secrets.GCP_PROJECT_ID }}

# # - name: Access gcloud CLI
# # run: |
# # gcloud account configure-docker

# - name: SSH into VM
# id: compute-ssh
# uses: google-github-actions/ssh-compute@v1
# with:
# instance_name: ${{ vars.GCP_INSTANCE_NAME }}
# zone: ${{ vars.GCP_INSTANCE_ZONE }}
# ssh_private_key: ${{ secrets.GCP_SSH_PRIVATE_KEY }}
# command: |
# cat /home/jerryhanksokafor/.env
# sudo docker ps
- name: Setup gcloud Auth
id: account
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}

- name: Setup gcloud CLI
uses: google-github-actions/setup-gcloud@v2
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}

- name: Access gcloud CLI
run: |
gcloud auth configure-docker
- name: Build docker-compose.yml
run: |
sed "s/DOCKER_IMAGE_NAME/${{secrets.DOCKERHUB_USERNAME}}\/${{env.DOCKER_IMAGE_NAME_STAGING}}/g" docker-compose-template.yml > docker-compose.yml
sed -i "s/DOCKER_IMAGE_NAME/${{secrets.DOCKERHUB_USERNAME}}\/${{env.DOCKER_IMAGE_NAME}}/g" docker-compose.yml
sed -i "s/DOCKER_CONTAINER_NAME_STAGING/${{env.DOCKER_CONTAINER_NAME_STAGING}}/g" docker-compose.yml
sed -i "s/DOCKER_CONTAINER_NAME/${{env.DOCKER_CONTAINER_NAME}}/g" docker-compose.yml
- name: Compose and copy .env file
run: |
echo "APP_API_BASE_URL=${{secrets.APP_API_BASE_URL}}" >> .env
cat .env
- name: SSH into VM
id: compute-ssh
uses: google-github-actions/ssh-compute@v1
with:
instance_name: ${{ vars.GCP_INSTANCE_NAME }}
zone: ${{ vars.GCP_INSTANCE_ZONE }}
ssh_private_key: ${{ secrets.GCP_SSH_PRIVATE_KEY }}
command: |
cat /home/jerryhanksokafor/.env
sudo docker ps
# # sudo docker run --name url-shortener --env-file /home/jerryhanksokafor/.env -p 8000:8000 jerryokafor/url-shortener
# # Example of using the output
# - name: Show result of SSH int Vm
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Version: 1.0

# FROM - Image to start building on.
FROM python:3.12-slim
FROM python:3.12.2-slim


# PROJECT SETUP
Expand Down
30 changes: 30 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: "3.8"

services:
staging:
profiles: [staging]
image: DOCKER_IMAGE_NAME_STAGING:latest
container_name: DOCKER_CONTAINER_NAME_STAGING
restart: unless-stopped
volumes:
- ./urls-shortener:/api
ports:
- "8000:8000"
- "80:8000"
- "443:8000"
environment:
- DJANGO_SETTINGS_MODULE=api.settings

# production:
# profiles: [production]
# image: DOCKER_IMAGE_NAME:latest
# container_name: DOCKER_CONTAINER_NAME
# restart: unless-stopped
# volumes:
# - ./urls-shortener:/api
# ports:
# - "8000:8000"
# - "80:8000"
# - "443:8000"
# environment:
# - DJANGO_SETTINGS_MODULE=api.settings

0 comments on commit 8aade00

Please sign in to comment.