update #42
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
name: Build Image for test | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: hello | |
SHORT_SHA: '' | |
on: | |
push: | |
branches: [ master ] | |
release: | |
types: [ published ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
outputs: | |
IMAGE_TAG: ${{ steps.get_short_sha.outputs.SHORT_SHA}} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Login to GitHub Packages | |
if: ${{ github.ref_type == 'branch' }} | |
run: echo "${{ secrets.SECRETS_GITHUB_TOKEN }}" | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin | |
- name: Get Short SHA | |
id: get_short_sha | |
run: | | |
SHORT_SHA=$(echo ${GITHUB_SHA} | cut -c1-7)" | |
echo "SHORT_SHA=$SHORT_SHA" >> $GITHUB_OUTPUT | |
echo "Short SHA: $SHORT_SHA" | |
- name: Build images | |
env: | |
IMAGE_TAG: ${{ steps.get_short_sha.outputs.SHORT_SHA}} | |
if: ${{ github.ref_type == 'branch' }} | |
run: make build ARGS="ghcr.io/${{ github.repository }}/" IMAGE_TAG="${IMAGE_TAG}" IMAGE_NAME=${{ env.IMAGE_NAME }} | |
- name: Push images to repository | |
env: | |
IMAGE_TAG: ${{ steps.get_short_sha.outputs.SHORT_SHA}} | |
if: ${{ github.ref_type == 'branch' }} | |
run: make push ARGS="ghcr.io/${{ github.repository }}/" IMAGE_TAG="${IMAGE_TAG}" IMAGE_NAME=${{ env.IMAGE_NAME }} | |
deploy_test: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Get Short SHA | |
id: get_short_sha | |
run: | | |
echo "SHORT_SHA=$(echo ${GITHUB_SHA} | cut -c1-7)" >> $GITHUB_ENV | |
echo "Short SHA: $SHORT_SHA" | |
- name: Deploy Test | |
uses: appleboy/[email protected] | |
env: | |
GITHUB_ACTOR: $GITHUB_ACTOR | |
SECRETS_GITHUB_TOKEN: ${{ secrets.SECRETS_GITHUB_TOKEN }} | |
IMAGE_NAME: ${{ env.IMAGE_NAME }} | |
IMAGE_TAG: ${{ needs.build.outputs.IMAGE_TAG}} | |
REGISTRY: ${{ github.repository }} | |
with: | |
host: ${{ secrets.REMOTE_HOST_TEST }} | |
username: ubuntu | |
key: ${{ secrets.SSH_PRIVATE_KEY_TEST }} | |
port: 22 | |
envs: GITHUB_ACTOR,SECRETS_GITHUB_TOKEN,IMAGE_NAME,IMAGE_TAG,REGISTRY | |
script: | | |
echo "$GITHUB_ACTOR $REGISTRY $IMAGE_TAG $IMAGE_NAME $SECRETS_GITHUB_TOKEN" > test.txt | |
echo "$SECRETS_GITHUB_TOKEN" | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin | |
docker stop $IMAGE_NAME && docker rm IMAGE_NAME | |
docker run -d --name $IMAGE_NAME ghcr.io/${REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG} |