Skip to content

Commit

Permalink
Update google-run2.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinOntiveros authored Jul 12, 2024
1 parent ee9af1a commit 5dac1bb
Showing 1 changed file with 21 additions and 37 deletions.
58 changes: 21 additions & 37 deletions .github/workflows/google-run2.yml
Original file line number Diff line number Diff line change
@@ -1,63 +1,47 @@
yaml
name: Build and Test Docker
name: Build and Deploy Locally

on:
push:
branches: [ "staging" ]

env:
IMAGE: geppetto
SERVICE_NAME: cloud-run-service

jobs:
build-and-test:
name: Setup, Build, and Test
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
environment: production

permissions:
contents: 'read'

steps:
- name: Checkout
uses: actions/checkout@v3

- name: List Files in the Directory
run: ls -la
- name: Log in to Docker Hub
run: echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_HUB_USERNAME }}" --password-stdin

- name: Build Docker Image
run: |
docker build \
--tag ${{ env.IMAGE }}:${{ github.sha }} \
--tag "${{ env.IMAGE }}:${{ github.sha }}" \
--build-arg GITHUB_SHA="${{ github.sha }}" \
--build-arg GITHUB_REF="${{ github.ref }}"
- name: Run Docker Container
run: |
docker run --name ${{ env.IMAGE }}-container -d -p 8080:8080 ${{ env.IMAGE }}:${{ github.sha }}
- name: Wait for Container Start
run: sleep 10
--build-arg GITHUB_REF="${{ github.ref }}" \
.
- name: Test Application
run: curl --fail http://localhost:8080

- name: Stop and Remove Docker Container
run: |
docker stop ${{ env.IMAGE }}-container
docker rm ${{ env.IMAGE }}-container
# Añadiendo pasos específicos para kustomize y kubectl
- name: Setup kustomize
- name: Push Docker Image to Docker Hub
run: |
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
sudo mv kustomize /usr/local/bin/
docker tag "${{ env.IMAGE }}:${{ github.sha }}" "${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.IMAGE }}:${{ github.sha }}"
docker push "${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.IMAGE }}:${{ github.sha }}"
- name: Verify kustomization presence
- name: Deploy Docker Container Locally
run: |
if [ ! -f ./kustomization.yaml ]; then
echo "Missing kustomization.yaml file"
exit 1
fi
docker run -d --name ${{ env.SERVICE_NAME }} -p 8080:8080 "${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.IMAGE }}:${{ github.sha }}"
- name: Set Image in Kustomize
run: ./kustomize edit set image us-central1-docker.pkg.dev/PROJECT_ID/docker-repository/${{ env.IMAGE }}:${{ github.sha }}
- name: Apply Kustomize configuration
run: |
./kustomize build . | kubectl apply -f -
docker run -d --name ${{ env.SERVICE_NAME }} -p 8080:8080 "${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.IMAGE }}:${{ github.sha }}"

0 comments on commit 5dac1bb

Please sign in to comment.