diff --git a/guestbook-go/.github/workflows/main.yml b/guestbook-go/.github/workflows/main.yml new file mode 100644 index 00000000..6a8874b9 --- /dev/null +++ b/guestbook-go/.github/workflows/main.yml @@ -0,0 +1,57 @@ +name: Publish Docker Image + +on: + push: + branches: ['master'] + +jobs: + build: + name: Push Docker Image to Docker Hub + runs-on: Ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Cache Docker Layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }} -buildx- + + - name: Run Tests + run: | + # Add comments to run your tests here + echo "Running tests..." + # Example: go test ./... + go test ./... + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and Push Docker Image + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: true + tags: | + ${{ secrets.DOCKER_USERNAME }}/guestbook-go:latest + ${{ secrets.DOCKER_USERNAME }}/guestbook-go:${{ github.sha }} + cache-from: type=local, src=/tmp/.buildx-cache + cache-to: type=local, dest=/tmp/.buildx-cache-new + + - name: Post Build Cleanup + run: rm -rf /tmp/.buildx-cache-new + + + + \ No newline at end of file