forked from CoinFabrik/geppetto
-
Notifications
You must be signed in to change notification settings - Fork 15
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
1 parent
ee9af1a
commit 5dac1bb
Showing
1 changed file
with
21 additions
and
37 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 |
---|---|---|
@@ -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 }}" |