|
39 | 39 | uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 |
40 | 40 | with: |
41 | 41 | images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 42 | + # This step creates `.env` fine with the environment variables for the production environment. |
| 43 | + - name: Generate Environment Variables File for Production |
| 44 | + run: | |
| 45 | + echo "PORT=$PORT" >> .env |
| 46 | + echo "BOJ_AUTO_LOGIN=$BOJ_AUTO_LOGIN" >> .env |
| 47 | + echo "BOJ_ONLINE_JUDGE=$BOJ_ONLINE_JUDGE" >> .env |
| 48 | + echo "BOJ_USER_AGENT=$BOJ_USER_AGENT" >> .env |
| 49 | + echo "MONGODB_URI=$MONGODB_URI" >> .env |
| 50 | + echo "SOLVEDAC_TOKEN=$SOLVEDAC_TOKEN" >> .env |
| 51 | + env: |
| 52 | + PORT: ${{ secrets.ENV_PORT }} |
| 53 | + BOJ_AUTO_LOGIN: ${{ secrets.ENV_BOJ_AUTO_LOGIN }} |
| 54 | + BOJ_ONLINE_JUDGE: ${{ secrets.ENV_BOJ_ONLINE_JUDGE }} |
| 55 | + BOJ_USER_AGENT: ${{ secrets.ENV_BOJ_USER_AGENT }} |
| 56 | + MONGODB_URI: ${{ secrets.ENV_MONGODB_URI }} |
| 57 | + SOLVEDAC_TOKEN: ${{ secrets.ENV_SOLVEDAC_TOKEN }} |
42 | 58 | # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. |
43 | 59 | # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see [Usage](https://github.com/docker/build-push-action#usage) in the README of the `docker/build-push-action` repository. |
44 | 60 | # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. |
@@ -71,11 +87,14 @@ jobs: |
71 | 87 | password: ${{ secrets.SSH_PASSWORD }} |
72 | 88 | port: ${{ secrets.SSH_PORT }} |
73 | 89 | script: | |
74 | | - IMAGE_ID=ghcr.io/${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 90 | + IMAGE_ID=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 91 | + IMAGE_ID=$(echo $IMAGE_ID | tr '[:upper:]' '[:lower:]') |
| 92 | + CONTAINER_ID=${{ env.IMAGE_NAME }} |
| 93 | + CONTAINER_ID=$(echo "CONTAINER_ID=Code-Poker/CodePoker-be" | sed -E 's#.*/##' | tr '[:upper:]' '[:lower:]') |
75 | 94 | docker pull $IMAGE_ID:main |
76 | | - docker stop codepoker-be |
77 | | - docker rm codepoker-be |
78 | | - docker run -d --name codepoker-be \ |
79 | | - -p ${{ secrets.SSH_PORT }}:${{ secrets.SSH_PORT }} \ |
| 95 | + docker stop $CONTAINER_ID |
| 96 | + docker rm $CONTAINER_ID |
| 97 | + docker run -d --name $CONTAINER_ID \ |
| 98 | + -p 6370:6370 \ |
80 | 99 | --restart=always \ |
81 | | - $IMAGE_ID:latest |
| 100 | + $IMAGE_ID:main |
0 commit comments